It may sound very silly question, but I want to clear myself

In confusion matrix we normally take values like below:

Actualvalue TRUE  FALSE
          1 18786 10177
          0  3135  5709

and calculate sensitivity = tp/(tp+fn) = table[0,0]/(table[0,0] + table[1,0])

If my confusion matrix will change to below (position of 0,1 and true false changed)

Actualvalue FALSE  TRUE
          0 5709   3135
          1  10177  18786

Can I still use the same formula (table[0,0]/(table[0,0] + table[1,0])) for sensitivity?


Don't depend on the row/column positions of the numbers in a confusion matrix to do your calculations. In your two matrices the relations between the actual and predicted numbers are the same, only their positions in the matrix are changed. If you used the matrix-position-based formula then you would get different values for sensitivity even though the underlying facts are the same. That doesn't make sense. Always use the true positive and false negative values for sensitivity, regardless of where they happen to show up in your matrix. (The same holds for other calculations from the confusion matrix.)

There can be so much confusion in calculating and using confusion matrices that I suggest always putting your data into the format seen in several Wikipedia pages, like this one. This has actual classes as columns, predicted classed as rows, and true positives in the top left. This makes it easier to check your results against the formulas in such pages. For your data:

PredictedValue     1    0
             1 18786 3135
             0 10177 5709

Do note, however, that the sensitivity value can depend on which of the 2 classes you happened to call "positive" or "1" or "TRUE" in the beginning. That is one of biggest confusions with confusion matrices.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.