Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (19.9k points)

Lets asumme I have the following test values:

y_test2 = [0, 0, 1, 1]

and the following prediction values:

y_pred2 = [1, 0, 1, 1]

So I have a binary classificaiton problem with {0,1}as classes. If i am using sklearn confusion_matrix:

confusion_matrix(y_test2, y_pred2)

array([[1, 1], #one 0 was predicted as 0 (TruePositive),  one 0 was predicted as 1 (FalseNegative)

       [0, 2]], dtype=int64) #two 1 were predicted as 1 (TrueNegatives)

So for me it is:

TP: 1

FN: 1

TN: 2

FP: 0

However, when I run the confusion_matrix with ravel, followed scikit learns documentation:

tn, fp, fn, tp = confusion_matrix(y_test2, y_pred2).ravel()

(1, 1, 0, 2)

Why is scikit interpretating the 1 as True values? And why is it not mentioned in the docs Is there any other issue I could face for binary classification with the naming convention? Is there any chance to avoid this?

1 Answer

0 votes
by (25.1k points)

If you look at the documentation closely it says:

“Thus in binary classification, the count of true negatives is C(0,0) , false negatives is C(1,0), true positives is C(1,1) and false positives is C(0,1) .”

So for your array:

array([[1, 1], [0, 2]], dtype=int64)

it is

TN: 1 FN: 0 TP: 2 FP: 1

Browse Categories

...