AWS机器学习Django Temp

2024-09-28 05:22:21 发布

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

我有一个来自AWS机器学习的反应(我只是展示了一些反应):

{u'Prediction': {u'predictedLabel': u'Luxemburgo', u'predictedScores': {u'Irlanda': 0.0003484287590254098, u'B\xe9lgica': 0.013423046097159386, u'Espa\xf1a': 0.002083213534206152, u'Grecia': 0.0014155727112665772, u'San Marino': 0.00233459216542542, u'Letonia': 0.0008684576023370028, u'Azerbaiy\xe1n': 0.0651199221611023, u'Finlandia': 0.0015709727304056287, u'Andorra': 0.00023321053595282137, u'Italia': 0.0007921983487904072, u'Vaticano': 0.011585880070924759, u'M\xf3naco': 0.01911487616598606, u'Dinamarca': 0.004232937004417181, u'Pa\xedses Bajos': 0.0007871986017562449, u'Islandia': 0.006683974526822567, u'Francia': 0.004822706338018179, u'Montenegro': 0.018228678032755852, u'Bielorrusia': 0.0024703771341592073, u'Alemania': ...

我想向用户展示django模板中的predictedScores,所以

{% for p in response.Prediction.predictedScores %}
    {{p}}
{% endfor %}

这给了我一个很好的国家名单,但我也想显示的可能性,我不能计算出如何访问它们。我相信这很简单,但我看不出来。你知道吗


Tags: 机器awssanpredictionespaxf1apredictedlabelmarino
1条回答
网友
1楼 · 发布于 2024-09-28 05:22:21

predictedScores是一个字典:要遍历dict的键和值,可以使用items()。你知道吗

{% for score_name, score_value in response.Prediction.predictedScores.items %}
    {{ score_name }}: {{ score_value }}
{% endfor %}

相关问题 更多 >

    热门问题