【问题标题】:AWS Machine Learning - Django TemplateAWS 机器学习 - Django 模板
【发布时间】:2017-07-12 19:01:18
【问题描述】:

我收到了来自 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 模板中向用户展示预测分数,所以我正在这样做

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

这给了我一个很好的国家列表,但我也想显示概率,我不知道如何访问它们。我确信它很简单,但我看不到它。

【问题讨论】:

    标签: python json django amazon-web-services django-templates


    【解决方案1】:

    predictedScores 是一个字典:要遍历字典的键和值,请使用 items()

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

    【讨论】:

    • 谢谢你——我知道我很笨。
    猜你喜欢
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2016-09-19
    • 2016-10-27
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    相关资源
    最近更新 更多