简体   繁体   中英

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

As the documentation for version 1.2.0 states, you need to call the function like

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 . You are trying to put one extra argument in: [0, 1, 2, 3] . Either it or one of the previous two arguments ( lab2d or pred2d ) should be removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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