繁体   English   中英

f1_score() 采用 2 个位置 arguments,但给出了 3 个位置 arguments(和 1 个仅关键字参数)

[英]f1_score() takes 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given

 from sklearn.metrics import f1_score


 F1_score = f1_score(lab2d, pred2d, [0, 1, 2, 3], average=None)
print("Validation Dice Coefficient.... ")
print("Background:", F1_score[0])
print("CSF:", F1_score[1])
print("GM:", F1_score[2])
print("WM:", F1_score[3])
 ```

这是错误

f1_score() takes 2 positional arguments but 3 positional arguments (and 1  keyword-only argument) were given

我尝试以不同的方式传递 arguments 但仍然出现相同的错误

正如 1.2.0 版的文档所述,您需要像这样调用 function

from sklearn.metrics import f1_score
y_true = [0, 1, 2, 0, 1, 2]
y_pred = [0, 2, 1, 0, 0, 1]
f1_score(y_true, y_pred, average='macro')

请注意,它接受 3 arguments: y_truey_pred和关键字参数average 您正试图在[0, 1, 2, 3]中添加一个额外的参数。 它或前两个 arguments ( lab2dpred2d )之一应该被删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM