Verta
Search…
Deploying a scikit-learn model
As mention in the deploying models guide, deploying models via Verta Inference is a two step process: (1) first create an endpoint, and (2) update the endpoint with a model.
This tutorial explains how Verta Inference can be used to deploy a scikit-learn model.

1. Create an endpoint

Users can create an endpoint using Client.create_endpoint() as follows:
1
census_endpoint = client.create_endpoint(path="/census")
Copied!

2. Updating the endpoint with a RMV

As discussed in the Registry Overview, there are multiple of ways to create an RMV for a scikit-learn model.
First, given a scikit-learn model object, users can use the sklearn convenience functions to create a Verta Standard Model.
1
from verta.environment import Python
2
3
model_version_v1 = registered_model.create_standard_model_from_sklearn(
4
model,
5
environment=Python(requirements=["scikit-learn"]),
6
name="v1",
7
)
Copied!
Alternatively, a scikit-learn model can be used as an artifact in a model that extends VertaModelBase.
1
import cloudpickle
2
with open("model.pkl", "wb") as f:
3
cloudpickle.dump(model, f)
4
5
from verta.registry import VertaModelBase
6
7
class CensusIncomeClassifier(VertaModelBase):
8
def __init__(self, artifacts):
9
self.model = cloudpickle.load(open(artifacts["serialized_model"], "rb"))
10
11
def predict(self, batch_input):
12
results = []
13
for one_input in batch_input:
14
results.append(self.model.predict(one_input))
15
return results
16
17
model_version_v2 = registered_model.create_standard_model(
18
model_cls=CensusIncomeClassifier,
19
environment=Python(requirements=["scikit-learn"]),
20
artifacts=artifacts_dict,
21
name="v2"
22
)
Copied!
Regardless of how a Registered Model Version has been created, the endpoint defined above can now be upated and we can make predictions against it.
1
census_endpoint = client.get_or_create_endpoint("census-model")
2
census_endpoint.update(model_version_v1, wait=True)
3
deployed_model = census_endpoint.get_deployed_model()
4
deployed_model.predict(X_test.values.tolist()[:5])
Copied!
The full code for this tutorial can be found here.
Last modified 3mo ago