Search code examples
pythonazure-machine-learning-service

AzureML multiple models stored in dictionary


Overview:

I have a unique Python model where we hold n trained random forest models in a dictionary. I tried to avoid this setup, but for the time being it's necessary. On my local, I can make predictions by passing a dataframe to a predict function and looping through the rows, calling the appropriate model for each row, like rf_models[model].predict().

In AzureML I created a toy model that allows me to go: Web Input -> Python Script -> Score Model -> Web output.

Challenge:

I need to be able to call the score_model, or specifically the predict method, from inside the "Python Script" function on AzureML so I can deal with the loops and n models stored in the dict. The results, either a JSON or dataframe, would be sent to AzureML's Web Output.

I found a link online (https://learn.microsoft.com/en-us/azure/machine-learning/machine-learning-execute-python-scripts) that got me close, but the example shows a model being trained and used to predict at the same time inside the same Python script, thus calling the predict method as a local variable and not calling a previously trained model. I found only limited documentation online to solve this problem and I could not get the rest of the way there. I'm unsure if this type of customization is not yet available or if I'm completely overlooking some key functionality.

Thank you for your assistance.


Solution

  • Here are two links that might help:

    1. AzureML Operationalization
    2. Example notebook that shows how to publish Python model as a web service. You would do a similar thing, only you would pickle the dictionary of your models instead.

    Note that this functionality is currently in preview mode.