我正在尝试遍历一系列预测和基本事实,并计算真正的积极因素。
这是我想到的解决方案:
tp = 0
for p, g in zip(predicted, ground_truth):
if p and g == True:
tp += 1
return tp
我得到一个错误消息说:SyntaxError: '返回'外部函数。但是返回值在函数内部。
试试这个:
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)
这应该返回:1
你需要用def
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
需要定义一个函数,def count_true(p, g)