为什么通过webservice API调用Azure ML分类模型时不返回概率分数?

2024-05-16 04:48:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Azure的新手,也是一位代码含量很低的数据科学家(这似乎不利于我)。无论如何!几天前,我在ML Studio中使用Azure AutoML培训了一个模型,并将最成功的模型注册为具有端点的Web服务。现在,当我使用下面的Python代码调用这个模型时,它只返回预测,而不返回概率分数。AutoML已将“Stackensemble”部署为分类问题的最佳模型。我有很多用Python编写的代码,我更喜欢一种适合我的代码的方法,而不是完全不同的方法。注意:HTTPs和get/post请求不是我的强项,因此任何简单易懂的解释都会对我非常有益。谢谢

我用来调用api的代码

resp = requests.post(scoring_uri, input_testdata_with_2obs, headers=headers) print (resp.text)

我得到的(仅预测):

{\'result\':[\'Loss\',\'Loss\']}

我还在其他帖子和Azure文档中在线找到了以下代码,但我不知道如何将其用于已部署的模型(培训后)。在我用来调用API的python代码中,以下代码需要放在哪里

best_run, fitted_model = automl_run.get_output() class_prob = fitted_model.predict_proba(X_test)


Tags: 方法run代码模型getmodel部署azure
1条回答
网友
1楼 · 发布于 2024-05-16 04:48:00

此链接应该有帮助:https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/how-to-track-experiments

from azureml.core import Webservice
import json

# if you called your service differently then change the name below
service = Webservice(ws, name="diabetes-service")

input_payload = json.dumps({
    'data': X_test[0:2].tolist(),
    'method': 'predict'  # If you have a classification model, you can get probabilities by changing this to 'predict_proba'.
})

output = service.run(input_payload)

print(output)

步骤3显示了如何通过API将“方法”:“predict_proba”添加到“data”下面的JSON文件中

相关问题 更多 >