简体   繁体   English

从 AutoML PredictResponse 对象返回分数

[英]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

You may use the this code 您可以使用此代码

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

It will provide you a dictionary for all the categories (Yes and No in your case) 它将为您提供所有类别的字典(在您的情况下是和否)
 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.

相关问题 如何从PredictResponse对象获取float_val? - How to get float_val from a PredictResponse object? 不接受 AutoML 语言实体提取 score_threshold 作为参数 - AutoML Language Entity Extraction score_threshold not accepted as a parameter 从 EvalML 使用 AutoML 时出现错误 AttributeError: 'DataTable' object has no attribute 'to_series' - While using AutoML from EvalML getting error AttributeError: 'DataTable' object has no attribute 'to_series' 为什么分类器的score函数与sklearn中的cross_val_score函数返回的结果完全不同? - Why the classifier's score function return a quite different result from cross_val_score function in sklearn? 为什么GridSearchCV的返回分数与直接运行模型返回的分数有如此不同? - Why GridSearchCV return score so different from the score returned by running model directly? 如何从Sklearn分类报告中返回精确度,召回率和F1分数的平均分数? - How to return average score for precision, recall and F1-score from Sklearn Classification report? Tensorflow Keras 模型:如何从历史对象中获得最高分 - Tensorflow Keras model: how to get the best score from a history object 从 PubSub 访问 AutoML 的 403 权限被拒绝 - 403 permission denied to access AutoML from PubSub Google Cloud Vision AutoML 和 TensorFlow Object 检测差异 - Google Cloud Vision AutoML and TensorFlow Object Detection Differences 返回分数按账户增加的次数 - Return number of score increases by account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM