Skip to main content

Adding models to the registry

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:

from sklearn import linear_model

# First, make a model
my_model = linear_model.LinearRegression()
my_model.fit([[1], [2], [3]], [2, 4, 6])

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

The linear regression named my_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")

You can also retrieve many models at once with mb.get_models.

models = mb.get_models(prefix="marketing/")

Next, use the model registry with a deployment.