Search code examples
azuremachine-learningazure-machine-learning-service

Deploying custom model on Azure ML Studio


In Azure ML Studio, we have the option of choosing a number of inbuilt ML models like Classification, Regression, etc. , which we can drag and drop to our workflow.

My question is, can I upload a custom ML model that I have built locally on my system in Python, and add it to the workflow?


Solution

    1. Take the model.pkl file, zip it, and upload it into Azure Machine Learning Studio. Click the “New” icon in the bottom left:
    2. In the pane that comes up, click on dataset, and then “From Local File”:
    3. Select the zip file where you stored your serialized model and click the tick. You expirement should look like this:
    4. Put the following code to run your classification experiment:
    import pandas as pd
    import sys
    import pickle
    
    def azureml_main(dataframe1 = None, dataframe2 = None):
        sys.path.insert(0,".\Script Bundle")
        model = pickle.load(open(".\Script Bundle\model.pkl", 'rb'))
        pred = model.predict(dataframe1)
        return pd.DataFrame([pred[0]])
    

    Update If you want to declare this experiment as an API you need to add web input and output to the Python script module. enter image description here