The PureML model registry provides a centralized location for users to store their models and manage their lifecycle collaboratively. This makes it easier for stakeholders to manage models and promotes transparency in accessing models for tests, deployment, audit, and other purposes.

With PureML, you can manage your models in the following ways:

  • Create models to track and assess their relevance using generic model data.
  • Automatically version models to efficiently organize model runs. PureML logs model parameters, metrics, and other metadata that changes for each registered model.
  • Fetch stored models and their metadata through our API.

By using the PureML model registry, you can streamline your model management processes and facilitate collaboration among your team members. This allows for greater efficiency, transparency, and accuracy in managing your models.

Creating Models

With the PureML model module, you can perform a variety of actions related to creating and managing models. Here’s an overview of the available methods:

Creating a Model To create a new model, import the pureml module and use the model.init method:

import pureml

pureml.model.init(label='FirstModel', readme='ReadME.md')

The name of the model to be created are required parameters. You can also provide an optional readme file path.

label parameter consists of model name in the following format:

_\<name>:\<version>_

For initializing a model, version is not required. So, we use <name>: as the label.

label should not contain any spaces. Special characters other than ”-” and ”_” are not allowed.

Created a model? No? Create one now. Yes? Here’s what you should do next.

Register Models

PureML assists you with creating, training, and tracking all of your machine learning project information, including ML models and datasets, using semantic versioning and full artifact logging.

This short tutorial will show you how to register and track machine learning models using PureML.

pip install pureml
pip install xgboost
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import xgboost as xgb
import pandas as pd
import pureml
from pureml.decorators.model import model

Train and Register your Model Version

We will train a XGBClassifier to predict the classes of samples from Iris dataset in this tutorial. This is a straightforward training function that returns the trained model and prints the accuracy of our model. We will utilize the Iris data from sklearn.

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
def train():
  xgb_model = xgb.XGBClassifier()
  xgb_model.fit(X_train, y_train)
  predictions = xgb_model.predict(X_test)

  acc = accuracy(y_test, predictions)
  print("accuracy: ", acc)

  return xgb_model

xgb_model = train()

Now let’s register our model to pureml

To register the model, add the @model decorator to the training function. PureML will register the returned trained model to your PureML project.

Let’s also replace print() with pureml.log() to register obtained model metrics to the project.

@model('iris_classifier')
def train():
    xgb_model = xgb.XGBClassifier()
    xgb_model.fit(X_train, y_train)
    predictions = xgb_model.predict(X_test)

    acc = accuracy(y_test, predictions)

    pureml.log(metrics={'accuracy':acc})
    print("accuracy: ", acc)

    return xgb_model

xgb_model = train()

Fetching a Model

Once you register your model to PureML, you can load the model from PureML using model module.

Let’s look at how to load and generate predictions with your model:

import pureml

model = pureml.model.fetch('iris_clasifier')
X, y = load_iris(return_X_y=True)
preds = model.predict(X)

By default, fetch method fetches latest version of the model. A particular version of a model can be fetched by providing version parameter as the following.

model = pureml.model.fetch('iris_classifier:v3')

Here, we have fetched the version v3 of the model iris_classifier.

print('Prediction: ', preds[0])

Listing Models

To list all available models, use the model.list method:

import pureml

pureml.model.list()

These methods make it easy to create and manage the models in PureML. By using them, you can streamline your model management workflows and improve collaboration among team members.