【问题标题】:How do you iterate through two list and count the true positive你如何遍历两个列表并计算真阳性
【发布时间】:2023-01-18 14:02:05
【问题描述】:

我正在尝试遍历一系列预测和基本事实并计算真正的积极因素。

这是我想出的解决方案:

    tp = 0
    for p, g in zip(predicted, ground_truth):
        if p and g == True: 
           tp += 1
        return tp

我收到一条错误消息:SyntaxError: 'return' outside function。但是返回在函数内部。

【问题讨论】:

  • 我没有看到函数,只有 for 循环
  • 如果您需要有关错误的帮助,则需要包含更多代码。无论如何,您可能应该使用 this 之类的东西而不是循环。

标签: python for-loop


【解决方案1】:
def count_true(predicted, ground_truth):
   tp = 0
    for p, g in zip(predicted, ground_truth):
        if p and g == True: 
           tp += 1
        return tp

count= count_true([True, False, True], [True, True, False])
print(count)

您需要使用 def 声明一个函数

【讨论】:

    猜你喜欢
    • 2020-10-13
    • 2016-02-03
    • 2010-12-12
    相关资源
    最近更新 更多