Skip to main content

Getting started your notebook

The model registry stores models for later retrieval. Like the rest of Modelbit, the registry is git-aware so it respects branches and can be reviewed during code reviews.

Storing your first model

To store a model in the registry, call mb.add_model:

# first, make a model
from sklearn import linear_model
model = linear_model.LinearRegression()
model.fit([[1], [2], [3]], [2, 4, 6])

# store the model, we'll call it "example_model"
mb.add_model("example_model", model)

The linear regression named model has been stored in the registry as example_model.

To fetch the model from the registry, call use mb.get_model:

# retrieve the model
my_model = mb.get_model("example_model")

# test that it works
my_model.predict([[5]])[0] # --> 9.999...

Storing many models

If you have several (or thousands) of models to store in the registry you'll want them organized. The model registry is organized like a file system, where models belong to directories.

To add several model in a various different directories, use mb.add_models:

mb.add_models({
"marketing/predictor1": model1,
"marketing/predictor2": model2,
"finance/fraud_scorer": model3,
"finance/latency_scorer": model4,
})

The model registry in the web app will show these models grouped into marketing and finance directories.

Like before, retrieving a model is done by name:

my_model = mb.get_model("marketing/predictor2")

Now that you can store and retrieve models, let's use the model registry with a deployment.