Skip to main content
Version: 3.2

Registry Operation

Register the model in model registry and transit it to given stage. Staging, Production or Archived.

# Initializing RandomForestClassifier
from katonic.ml.classification import Classifier

clf = Classifier(X_train, X_test, y_train, y_test, exp_name)
clf.RandomForestClassifier()
result = clf.stagging(
run_id='91ebd975b96f40348523ce924976de0b',
model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned',
stage="Production"
)
>>> Registered model 'my-ne2-exp_21_gradient_boosting_classifier_tuned' already exists. Creating a new version of this model...
>>> 2022/03/29 12:20:01 INFO mlflow.tracking._model_registry.client: Waiting up to 300 seconds for model version to finish creation.
>>> Model name: my-ne2-exp_21_gradient_boosting_classifier_tuned, version 9
>>> Created version '9' of model 'my-ne2-exp_21_gradient_boosting_classifier_tuned'.
result
>>> name: "my-ne2-exp_21_gradient_boosting_classifier_tuned"
>>> version: "9"
>>> creation_timestamp: 1648556401684
>>> last_updated_timestamp: 1648556401701
>>> user_id: ""
>>> current_stage: "Production"
>>> description: ""
>>> source: "s3://models/21/91ebd975b96f40348523ce924976de0b/artifacts"
>>> run_id: "91ebd975b96f40348523ce924976de0b"
>>> status: READY
>>> run_link: ""

Change Stage of the Modelโ€‹

Register the model in model registry and transit it to given stage. Staging, Production or Archived.

result = clf.stagging(
run_id='91ebd975b96f40348523ce924976de0b',
model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned',
stage="Staging"
)
>>> Registered model 'my-ne2-exp_21_gradient_boosting_classifier_tuned' already exists. Creating a new version of this model...
>>> 2022/03/29 12:15:47 INFO mlflow.tracking._model_registry.client: Waiting up to 300 seconds for model version to finish creation.
>>> Model name: my-ne2-exp_21_gradient_boosting_classifier_tuned, version 8
>>> Created version '8' of model 'my-ne2-exp_21_gradient_boosting_classifier_tuned'.
result
>>> name: "my-ne2-exp_21_gradient_boosting_classifier_tuned"
>>> version: "8"
>>> creation_timestamp: 1648556147683
>>> last_updated_timestamp: 1648556147704
>>> user_id: ""
>>> current_stage: "Staging"
>>> description: ""
>>> source: "s3://models/21/91ebd975b96f40348523ce924976de0b/artifacts"
>>> run_id: "91ebd975b96f40348523ce924976de0b"
>>> status: READY
>>> run_link: ""
result = clf.stagging(
run_id='91ebd975b96f40348523ce924976de0b',
model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned',
stage="Archived"
)
>>> Registered model 'my-ne2-exp_21_gradient_boosting_classifier_tuned' already exists. Creating a new version of this model...
>>> 2022/03/29 12:13:54 INFO mlflow.tracking._model_registry.client: Waiting up to 300 seconds for model version to finish creation.
>>> Model name: my-ne2-exp_21_gradient_boosting_classifier_tuned, version 7
>>> Created version '7' of model 'my-ne2-exp_21_gradient_boosting_classifier_tuned'.
result
>>> name: "my-ne2-exp_21_gradient_boosting_classifier_tuned"
>>> version: "7"
>>> creation_timestamp: 1648556034415
>>> last_updated_timestamp: 1648556034431
>>> user_id: ""
>>> current_stage: "Archived"
>>> description: ""
>>> source: "s3://models/21/91ebd975b96f40348523ce924976de0b/artifacts"
>>> run_id: "91ebd975b96f40348523ce924976de0b"
>>> status: READY
>>> run_link: ""

View Model Versionsโ€‹

This function returns the model versions if match with filter string.

from katonic.ml.util import model_versions
model_versions(model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned')
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=1
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=2
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=3

View Previous Model Versionโ€‹

Return list of all previous versions of registered model.

from katonic.ml.util import previous_version
previous_version(model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned')
>>> ['1', '2']

Delete Model Versionโ€‹

Delete the model versions of given version list.

from katonic.ml.util import model_versions, delete_model_version
delete_model_version(
model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned',
ver_list=['1']
)
model_versions(model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned')
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=2
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=3

Upload Model Artifactsโ€‹

Store joblib objects in model artifact.

from katonic.ml.util import log_data
log_data(
prun_id='91ebd975b96f40348523ce924976de0b',
data_obj=X_test,
location='csv'
)

Load Modelโ€‹

Load a model from a model URI.

from katonic.ml.classification import Classifier
clf = Classifier(X_train, X_test, y_train, y_test, exp_name)
artifacts = "s3://models/21/91ebd975b96f40348523ce924976de0b/artifacts"
model_name = 'my-ne2-exp_21_gradient_boosting_classifier_tuned'
location = artifacts + "/" + model_name
model = clf.load_model(location)
model
>>> GradientBoostingClassifier(learning_rate=0.9, min_samples_leaf=5, n_estimators=90)

Delete Registered Modelโ€‹

Delete registered model versions.

from katonic.ml.util import delete_model_version
delete_model_version(
model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned',
ver_list=['2']
)
model_versions(model_name='my-ne2-exp_21_gradient_boosting_classifier_tuned')
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=3
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=4
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=5
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=6
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=7
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=8
>>> name=my-ne2-exp_21_gradient_boosting_classifier_tuned; run_id=91ebd975b96f40348523ce924976de0b; version=9