I need to evaluate various performance metrics like accuracy, specificity, sensitivity, recall rate, F score etc. My confusion matrix is as follows.

[[80, 5, 1], [16, 20, 0], [12, 1, 0]]

I'd like if someone could show me the formulae or a python program for calculating the same. Also, if you know any other metrics apart from these, please tell. I know how to calculate using formulae for a 2-class confusion matrix but I'm not sure for a 3-class matrix.


1 Answer 1


Accuracy can be easily calculated from the matrix by using diag sum / total.

Other metrics is really a one vs. rest (From wikipedia: strategy involves training a single classifier per class, with the samples of that class as positive samples and all other samples as negatives.)

Think about it, these metrics are defined in terms of "positive" or "negative", how would we define it when we have multiple classes.

To conclude, you will have specificity, sensitivity, recall rate, F score for each class. And a python package can do this for you automatically when you have multiple classes.

Here is an example from python documentation:

enter image description here

  • $\begingroup$ This helped a lot! Thank you! $\endgroup$ May 10, 2020 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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