【发布时间】:2016-05-29 18:06:50
【问题描述】:
当所述“实际”元素等于 1(“真阳性”的数量)时,我正在尝试计算列表中“预测”中的元素等于“实际”列表中相应元素的次数。
这是我的代码:
def F_approx(predicted, actual):
est_tp = np.sum([int(p == a) if a for p in predicted for a in actual])
est_fn = np.sum([int(p !=a) if a for p in predicted for a in actual])
est_recall = est_tp / (est_tp + est_fn)
pr_pred_1 = np.sum([int(p == 1) for p in predicted]) / len(predicted)
est_f = np.power(est_recall, 2) / pr_pred_1
return(est_f)
这在 我的 眼中看起来是正确的,但我得到一个错误:
File "<ipython-input-17-3e11431566d6>", line 2
est_tp = np.sum([int(p == a) if a for p in predicted for a in actual])
^
SyntaxError: invalid syntax
感谢您的帮助。
【问题讨论】:
标签: python syntax-error list-comprehension