[英]Return Score from AutoML PredictResponse Object
I'm trying to pull the score values out of my google automl PredictResponse Object.我正在尝试从我的 google automl PredictResponse 对象中提取分数值。 the object returned from the API looks as follows:
从 API 返回的对象如下所示:
payload {
classification {
score: 0.989063024521
}
display_name: "No"
}
payload {
classification {
score: 0.0109369996935
}
display_name: "Yes"
}
I've gotten close using this:我已经接近使用这个:
result.payload[1]
Which returns:返回:
classification {
score: 0.0109369996935
}
display_name: "Yes"
But I still can't get to just the score for a yes or a no.但我仍然不能只得出是或否的分数。
I've tried using simplejson, but the PredictResponse Object doesn't play nice with that either.我尝试过使用 simplejson,但 PredictResponse 对象也不能很好地使用它。 Is there a function within the Object I can use to get to the Score for yes and the score for no?
对象中是否有一个函数可以用来获取是的分数和否的分数? Appreciate the help!
感谢帮助!
result.payload[1].classification.score
d = {}
for i in range(len(response.payload)):
d[response.payload[i].display_name] = response.payload[i].classification.score
d = {}
for i in range(len(response.payload)):
d[response.payload[i].display_name] = response.payload[i].classification.score
predicted_data = []
for i in range(len(response.payload)):
predicted_data.append({
"key": response.payload[i].display_name,
"value": response.payload[i].classification.score
})
key-value list of payload objects有效负载对象的键值列表
You can extract the display_name field using the following:您可以使用以下方法提取 display_name 字段:
result.payload[N].display_name
From the Vision and Natural Language AutoML documentation, you can use the loop below to return the display_name of your predictions.在Vision and Natural Language AutoML 文档中,您可以使用下面的循环来返回您的预测的 display_name。
for result in response.payload:
print("Predicted class name: {}".format(result.display_name))
这是您问题的答案:
result.payload[0].display_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.