# Confused about false positive and false negative in confusion matrix?

I am working on binary classification for classifying cancer=1 and no-cancer=0, I use confusion matrix from sklearn, this is my confusion matrix on test set:

 # confusion matrix
[[18  0]
[ 7 15]]

# in my reading the order is:
TN=18
FP=0
FN=7
TP=15


but in some tutorials, I see different ordering for FP and FN, some said same as my reading,See here, but other said reverse of FP and FN, see here. my question is which one is true in my case? please give me a reference to be sure about the answer.

• It's really a shame that software (perhaps your coding?) doesn't label the rows and columns with the variable names used to create them.
– 42-
Nov 20, 2018 at 17:41

## 1 Answer

Think about the order of your test and prediction sets when constructing the confusion matrix. Here is a piece from one of my codes.

cm = confusion_matrix(y_test, y_pred)

print(cm)

Output:
[[TN FP]

[ FN TP]]

However, if I used:

cm = confusion_matrix(y_pred, y_test)

print(cm)

Output:
[[TN FN]

[ FP TP]]

That occurs since the predictions of the model are presented in the rows instead of columns now. Also confusion matrices can be NxN, or the classes may not be labeled as either 0 or 1. You can also change the places of TN and TP, think what should happen if you had classes named as 9 and 10. In other words, decision of Negative/Positive signs are our decision; we say what they are (hopefully in a reasonable way).

Hope I could help, please do not hesitate to ask more. Regards.

• In my code test_cm = confusion_matrix(y_act, y_pred), this means am right? Nov 20, 2018 at 13:59
• Yes, you are right. However, never forget that you can choose class 0 to be Pozitive rather than class 1 or vice versa. It depends on your viewpoint. There is not a strict structure of a confusion matrix. Nov 20, 2018 at 22:11