Search code examples
pythonazurescikit-learnpython-moduleazure-machine-learning-service

Adding python modules to AzureML workspace


I've been working recently on deploying a machine learning model as a web service. I used Azure Machine Learning Studio for creating my own Workspace ID and Authorization Token. Then, I trained LogisticRegressionCV model from sklearn.linear_model locally on my machine (using python 2.7.13) and with the usage of below code snippet I wanted to publish my model as web service:

from azureml import services

@services.publish('workspaceID','authorization_token')
@services.types(var_1= float, var_2= float)
@services.returns(int)

def predicting(var_1, var_2):
    input = np.array([var_1, var_2].reshape(1,-1)
return model.predict_proba(input)[0][1]

where input variable is a list with data to be scored and model variable contains trained classifier. Then after defining above function I want to make a prediction on sample input vector:

predicting.service(1.21, 1.34)

However following error occurs:

RuntimeError: Error 0085: The following error occurred during script 
evaluation, please view the output log for more information:

And the most important message in log is:

AttributeError: 'module' object has no attribute 'LogisticRegressionCV'

The error is strange to me because when I was using normal sklearn.linear_model.LogisticRegression everything was fine. I was able to make predictions sending POST requests to created endpoint, so I guess sklearn worked correctly. After changing to LogisticRegressionCV it does not.

Therefore I wanted to update sklearn on my workspace.

Do you have any ideas how to do it? Or even more general question: how to install any python module on azure machine learning studio in a way to use predict functions of any model I develpoed locally?

Thanks


Solution

  • For installing python module on Azure ML Studio, there is a section Technical Notes of the offical document Execute Python Script which introduces it.

    The general steps as below.

    1. Create a Python project via virtualenv and active it.
    2. Install all packages you want via pip on the virtual Python environment, and then
    3. Package all files and directorys under the path Lib\site-packages of your project as a zip file.
    4. Upload the zip package into your Azure ML WorkSpace as a dataSet.
    5. Follow the offical document to import Python Module for your Execute Python Script.

    For more details, you can refer to the other similar SO thread Updating pandas to version 0.19 in Azure ML Studio, it even introduced how to update the version of Python packages installed by Azure.

    Hope it helps.