code-on-computer-screen.jpg

From model fitting to production in seconds

 ·

Putting ML models in production is a challenge; over 60 percent of models never actually make it to production. This need not be the case: putting models into production efficiently can be done using only a few lines of code.

Model fitting

As fitting is not the aim of this tutorial, I will just fit an XGBoost model on the standard scikit-learn breastcancer data:

# Get the data:
from sklearn.datasets import load_breast_cancercancer = load_breast_cancer()X = cancer.data
y = cancer.target# And fit the model:
import xgboost as xgbxgb_model = xgb.XGBClassifier(objective="binary:logistic", random_state=42)
xgb_model.fit(X, y)

(I am ignoring model checking and validation; let’s focus on deployment)

Deploying the model

Now we have the fitted model; let’s deploy it using the sclblpy package:

# Model deployment using the sclblpy package:
import sclblpy as sp# Example feature vector and docs (optional):
fv = X[0, :]  
docs = {}  
docs['name'] = "XGBoost breast cancer model"# The actual deployment: just one line...
sp.upload(xgb_model, fv, docs)

Done.

Using the deployed model

Within seconds after running the code above I received the following email:

From model fitting to production in seconds

Clicking the big blue button get’s me to a page where I can directly run inferences:

From model fitting to production in seconds

While this is nice, you probably want to make a nicer application to use the deployed model. Simply copy-paste code you need for your project:

From model fitting to production in seconds

And off you go!

Wrap up

There is much more to say about model deployment (and about doing so efficiently: the procedure above actually transpiles your model to WebAssembly to make it efficient and portable), I won’t.

This is just the shortest tutorial I could think of.

Maurits KapteinFrom model fitting to production in seconds