Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I analyze a confusion matrix?

When I print out scikit-learn's confusion matrix, I receive a very huge matrix. I want to analyze what are the true positives, true negatives etc. How can I do so? This is how my confusion matrix looks like. I wish to understand this better.

[[4015  336    0 ...,    0    0    2]
 [ 228 2704    0 ...,    0    0    0]
 [   4    7   19 ...,    0    0    0]
 ..., 
 [   3    2    0 ...,    5    0    0]
 [   1    1    0 ...,    0    0    0]
 [  13    1    0 ...,    0    0   11]]
like image 916
minks Avatar asked Dec 25 '22 09:12

minks


2 Answers

IIUC, your question is undefined. "False positives", "true negatives" - these are terms that are defined only for binary classification. Read more about the definition of a confusion matrix.

In this case, the confusion matrix is of dimension N X N. Each diagonal represents, for entry (i, i) the case where the prediction is i and the outcome is i too. Any other off-diagonal entry indicates some mistake where the prediction was i and the outcome is j. There is no meaning to "positive" and "negative in this case.

You can find the diagnoal elements easily using np.diagonal, and, following that, it is easy to sum them. The sum of wrong cases is the sum of the matrix minus the sum of the diagonal.

like image 82
Ami Tavory Avatar answered Dec 29 '22 07:12

Ami Tavory


Terms like true positive,false positive, etc. refer to binary classification. Whereas the dimensionality of your confusion matrix is greater then two. So you can talk only about the number of observations known to be in group i but predicted to be in group j (definition of confusion matrix).

like image 20
Александр Гришин Avatar answered Dec 29 '22 06:12

Александр Гришин