-
-
Notifications
You must be signed in to change notification settings - Fork 34
confusion matrix
The confusion matrix is confusing just like its name, it can be easy to read it when it is just a 2x2 matrix but as the dimensions of this matrix increases in a multiclass classification a lot of people lose a clue.
The matrix itself doesn't carry much helpful information but the classification matrix coming out of the confusion matrix is all you need to care about.
CS 0 20:53:31.049 Confusion Matrix
CS 0 20:53:31.049 [[97,60]
CS 0 20:53:31.049 [63,80]]
CS 0 20:53:31.049
CS 0 20:53:31.049 Classification Report
CS 0 20:53:31.049
CS 0 20:53:31.049 _ Precision Recall Specificity F1 score Support
CS 0 20:53:31.049 1.0 0.61 0.62 0.56 0.61 157.0
CS 0 20:53:31.049 0.0 0.57 0.56 0.62 0.57 143.0
CS 0 20:53:31.049
CS 0 20:53:31.049 Accuracy 0.59
CS 0 20:53:31.049 Average 0.59 0.59 0.59 0.59 300.0
CS 0 20:53:31.049 W Avg 0.59 0.59 0.59 0.59 300.0
Note that: True Positives are the diagonal elements of the confusion matrix, False Positives are the sum of the column (excluding the diagonal element), and False Negatives are the sum of the row (excluding the diagonal element).
This is the measure of accuracy that the specific class was predicted
It is calculated as:
Precision = TP/ TP+FP
Where FP - Is the sum of the values in the corresponding column, excluding the TP
Commonly called sensitivity, it corresponds to the True Positive Rate of the considered class
It is calculated as
Recall = Sensitivity = TP/(TP+FN)
Corresponds to the true Negative rate of the considered class
Calculated as;
Specificity = TN/(TN+FP)
The F1 score is a measure of a classifier's performance that takes into account both precision and recall.
Calculated as:
f1 score = 2 x (Precision x recall)/ (Precision + Recall)
Things to Notice:
- The total number of test examples of any class would be the sum of the corresponding row (i.e TN and FN for that class)
- The total number of FN's for a class is the sum of all the values in the corresponding row(Excluding TP)
- The total number of FP's for a class is the sum of the values in the corresponding column(excluding TP)
- The total number of TN's for a certain class will be the sum of all the columns and rows excluding that class row and column