Search code examples
azureazure-machine-learning-service

How to make prediction after model registration in azure?


I created a simply model and then registered in azure. How can I make a prediction?

from sklearn import svm
import joblib
import numpy as np

# customer ages
X_train = np.array([50, 17, 35, 23, 28, 40, 31, 29, 19, 62])
X_train = X_train.reshape(-1, 1)
# churn y/n
y_train = ["yes", "no", "no", "no", "yes", "yes", "yes", "no", "no", "yes"]

clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(X_train, y_train)

joblib.dump(value=clf, filename="churn-model.pkl")

Registration:

from azureml.core import Workspace
ws = Workspace.get(name="myworkspace", subscription_id='My_subscription_id', resource_group='ML_Lingaro')

from azureml.core.model import Model
model = Model.register(workspace=ws, model_path="churn-model.pkl", model_name="churn-model-test")

Prediction:

from azureml.core.model import Model
import os

model = Model(workspace=ws, name="churn-model-test")
X_test = np.array([50, 17, 35, 23, 28, 40, 31, 29, 19, 62])
model.predict(X_test) ???? 

Error: AttributeError: 'Model' object has no attribute 'predict'


Solution

  • great question -- I also had the same misconception starting out. The missing piece is that there's a difference between model 'registration' and model 'deployment'. Registration is simply for tracking and for easy downloading at a later place and time. Deployment is what you're after, making a model available to be scored against.

    There's a whole section in the docs about deployment. My suggestion would be to deploy it locally first for testing.