Version Model
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:dev')
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:dev')
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:dev:v3')
Here, we have fetched the version v3
of the model iris_classifier
.
print('Prediction: ', preds[0])
Submit, approve and reject model version in review
By providing a comprehensive set of metrics and visualizations, PureML makes it easy to identify and correct any issues with its review feature and allows you to evaluate the quality of their data and the accuracy of their model. Owner can approve or reject to add in production.