简体   繁体   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])
 ```

This is the error这是错误

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

I tried to pass the arguments in diffrerent ways but still got the same error我尝试以不同的方式传递 arguments 但仍然出现相同的错误

As the documentation for version 1.2.0 states, you need to call the function like正如 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')

Please note that it accepts 3 arguments: y_true , y_pred and keyword argument average .请注意,它接受 3 arguments: y_truey_pred和关键字参数average You are trying to put one extra argument in: [0, 1, 2, 3] .您正试图在[0, 1, 2, 3]中添加一个额外的参数。 Either it or one of the previous two arguments ( lab2d or pred2d ) should be removed.它或前两个 arguments ( lab2dpred2d )之一应该被删除。

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

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