简体   繁体   中英

Azure ML Web Service + Python for Querying Pandas Data Frame

I want to use Azure ML Web Service for a non machine learning task with Python. The goal is the following:

I have a Pandas DF like this:

   Id   Value
0  111  0.1
1  222  7.3
2  333  3.1
3  444  5.0

I can query this DF successfully (what is the value of a certain row by Id?):

float(df.loc[pot['Id'] == 222, 'Value'])

Now, I want to deploy a function in Azure ML Web Service with this functionality where a function uses an uploaded data set as fix lookup table. I constructed the function which gets an Id number as argument, looks for the value in the pre-uploade dataset and gives it back as a float:

from azureml import services
import pandas as pd

@services.publish(workspace_id, workspace_token)
@services.types(id=int)
@services.returns(float)
def my_func(id):
    my_df = ws.datasets["uploaded_df.csv"].to_dataframe()
    return float(my_df.loc[cent['Id'] == id, 'Value'])

I can deploy it on Azure Web Services but when I try to run a test query It gets stuck (no way even to peep into the details). What is the problem here?

Let me first describe exactly what's happening here to help you better understand why it's failing.

What does the @services annotation do?

  1. It actually constructs an experiment DAG with a single "Execute Python Script" module in AML Studio (studio.azureml.net or the regional equivalent)
  2. Its contents unpack your defined function and apply it against the incoming data

What does the Workspace object do?

It connects to the Studio API that was provided and can extract datasets as you use in "ws.datasets".

So why doesn't it work?

It doesn't work because EPS is now running in a multitenant service without network access, and your function is now being blocked by the sandbox (even if you were to reinitialize the workspace object inside your function - I don't know what actually happens when an http client is closed over and rehydrated later)

What can I do?

  1. You can add the attach annotation to more directly solve the first problem I see here: https://github.com/Azure/Azure-MachineLearning-ClientLibrary-Python/blob/master/azureml/services.py#L68
  2. I personally would copy the code to Studio and publish the web service from there - that way you can iterate on your code and see error messages more quickly before deploying the service, which is harder to diagnose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM