Part 8_Confusion Matrix
Part 8_Confusion Matrix
CLASSIFIER
Need for Confusion Matrix
Classification Models have multiple output categories. Most error measures will
tell us the total error in our model, but we cannot use it to find out individual
instances of error in our model.
TOTAL
ERROR
INPUT CLASSIFIER ERROR
MEASURE SCORE
MULTIPLE OUTPUT
LABELS/CATEGORIES
Need for Confusion Matrix
During classification, we also have to overcome the limitations of accuracy. Accuracy can be misleading
for classification problems. If there is a significant class imbalance, a model might predict the majority
class for all cases and have a high accuracy score.
INBOX
TRUE FALSE
POSITIVE POSITIVE
PREDICTED
HEART DISEASE PREDICTION
ACTUAL ACTUAL
POSITIVE NEGATIVE
CLASSIFY
THE INCOME
INTO
i) >50k
ii) <=50k
Confusion Matrix Example
150 0 150 10
0 150 20 120
2XPrecisionXRecall
Precision + Recall
CALCULATIONS FOR OUR EXAMPLE
CLASSIFIER MODEL OUTPUT
Accuracy: The proportion of total
number of predictions that were
correct.
150 10
20 120
150+120
Accuracy:
150+120+20+10
MODEL
Accuracy: = (270/300) = 0.9 OR 90% OUTPUT
CALCULATIONS FOR OUR EXAMPLES
Precision: The proportion of CLASSIFIER MODEL OUTPUT
correct positive predictions.
150 10
150
Precision:
150+10 20 120
150 10
150
Recall:
150+20 20 120
2XPrecisionXRecall
Precision + Recall 150 10
2*0.93*0.88
F1-Score:
0.93+0.88 20 120
ADELIE 39 0 2
FIND THE
ACCURACY,
CHINSTRAP 12 10 1
PRECISION, RECALL
AND F1 SCORE.
GENTOO 6 1 29
Confusion Matrix Example 2
ADELIE
TP = 39 (Cell 1)
ADELIE CHINSTRAP GENTOO
FN = 0+2 = 2 0 2
ADELIE 39
(Cell 2 + Cell 3)
TN = 10+1+1+29= 41 (Cell 5
+ Cell6 + Cell 8 + Cell9 ) GENTOO 6 1 29
Confusion Matrix Example 2
Accuracy: The proportion of total
number of predictions that were
correct.
ADELIE CHINSTRAP GENTOO
ADELIE 39 0 2
39+41 10
Accuracy: CHINSTRAP 12 1
39+18+41+2
ADELIE 39 0 2
39
Precision:
39+18
CHINSTRAP 12 10 1
ADELIE 39 0 2
39
Recall:
39+2
CHINSTRAP 12 10 1