I came across following piece of code:
>>> from sklearn.metrics import classification_report
>>> y_true = [2,1,1,1]
>>> y_pred = [False,True,False,True]
>>> print(classification_report(y_true, y_pred))
precision recall f1-score support
0 0.00 0.00 0.00 0
1 1.00 0.67 0.80 3
2 0.00 0.00 0.00 1
accuracy 0.50 4
macro avg 0.33 0.22 0.27 4
weighted avg 0.75 0.50 0.60 4
I am unable to understand how sklearn performs mapping between labels in y_true
and y_pred
arrays. That is, how it determines, whether False
is same as 2
or 1
and same is the case with True
?
PS: I did not found any details in the doc.
CodePudding user response:
In python, True=1
and False=0
.
So,
y_pred = [False,True,False,True]
means the same as
y_pred = [0,1,0,1]
This means, this code will yield exactly the same results as your code:
y_true = [2,1,1,1]
y_pred = [0,1,0,1]
print(classification_report(y_true, y_pred))