BaseTen
Search…
scikit-learn

Deploying a scikit-learn model

BaseTen has great support for deploying and serving your scikit-learn models out of the box. Models made with scikit-learn can be deployed directly from in-memory objects.
Deploying a scikit-learn model is as simple as
1
import baseten
2
baseten_model = baseten.deploy(
3
my_model,
4
model_name='My first model',
5
)
Copied!
If you have already saved your model (e.g. pickled it), just load it back into memory, test it to ensure it works, and deploy as in the above.

An example

1
import baseten
2
from sklearn.ensemble import RandomForestClassifier
3
from sklearn.datasets import load_iris
4
5
iris = load_iris()
6
data_x = iris['data']
7
data_y = iris['target']
8
rfc = RandomForestClassifier()
9
rfc.fit(data_x, data_y)
10
11
# => RandomForestClassifier(n_estimators=100, ...)
12
13
baseten_model = baseten.deploy(
14
rfc,
15
model_name='Iris RFC',
16
target_directory='rfc_iris'
17
)
18
19
INFO To build this model server locally execute `docker build -f rfc_iris/sklearn-server.Dockerfile rfc_iris -t iris_rfc`
20
INFO To run this model server locally execute `docker run --rm -p 8080:8080 iris_rfc`
21
INFO To use the Python shell locally execute `docker run --rm -it iris_rfc python3`
22
INFO Serializing Iris RFC scaffold.
23
INFO Making contact with BaseTen 👋 👽
24
INFO 🚀 Uploading model to BaseTen 🚀
25
Upload Progress: 100% |████████████████████████████████████████████████████████████████████████████████████████████████████| 43.5k/43.5k
26
INFO 🔮 Upload successful!🔮
27
INFO Successfully created version xxxxxxx forIris RFC.
28
INFO Deploying model version.
29
INFO 🏁 The model is being deployed right now 🏁
30
INFO ----------------------------------------------------------------------------------------
31
INFO | Visit https://app.baseten.co/models/xxxxxxx/versions/xxxxxxx for deployment status |
32
INFO ----------------------------------------------------------------------------------------
Copied!

Calling your model from the client

Once your model is deployed, you can call it via the client:
1
baseten_model.predict(data_x[0:5]) # [0,0,0,0,0]
Copied!
Last modified 2mo ago