How to deploy a scikit learn regression model as a web service?

Nuno Nogueira 76 Reputation points
2021-08-24T16:05:22.53+00:00

Hello,

I find the documentation related with ML model deployment overwhelming and I'm struggling with the most basic "Hello world" tutorial even after several days of research.

All I want is to deploy the most basic model as a web service that can be consumed via an API through Power BI or any other web app to serve as a POC. Then we can think about "scale", "dockers", "containers", etc...

This is my code in Python 3.6:

import joblib

from sklearn.datasets import load_diabetes
from sklearn.linear_model import Ridge    

dataset_x, dataset_y = load_diabetes(return_X_y=True)

model = Ridge().fit(dataset_x, dataset_y)

joblib.dump(model, 'sklearn_regression_model.pkl')

This model as features as an array like:

array([[ 0.03807591,  0.05068012],[ ... , ...]])

As you can see, I've got the model serialized into a sklearn_regression_model.pkl file, I've also got the ML environment setup in Azure ML, a compute instance, I'm familiar with Python and the designer and prefer notebooks.

How can I deploy this model through an API like:

https://api.xxx.com&parameters....

Thanks for any help!

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,334 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,966 Reputation points Moderator
    2021-08-25T17:00:18.437+00:00

    Hello,

    Thanks for reaching out to us. Please refer to this guidance to deploy your model and service. https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-and-where?tabs=azcli#deploy-again-and-call-your-service

    Please refer to deploy from local file for your scenario. The workflow is similar no matter where you deploy your model:

    Register the model - Please register from local file
    Prepare an entry script
    Prepare an inference configuration
    Deploy the model locally to ensure everything works
    Choose a compute target
    Re-deploy the model to the cloud
    Test the resulting web service

    Hope this helps.

    Regards,
    Yutong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.