CAB212 · Unit 6: Evaluation and practice
Confusion matrix, precision, recall, F1 and ROC-AUC
11 practice questions
Key points
- Precision = TP/(TP+FP); recall = TP/(TP+FN)
- F1 = harmonic mean
- AUC 0.5 = random
- Accuracy misleads on imbalanced data
For a binary classifier the confusion matrix counts TP, FP, FN and TN.
- Accuracy = (TP + TN) / total
- Precision = TP / (TP + FP): of predicted positives, how many are right
- Recall (sensitivity, TPR) = TP / (TP + FN): of actual positives, how many are found
- Specificity = TN / (TN + FP)
- F1 = 2 * precision * recall / (precision + recall), the harmonic mean
Worked example: TP=40, FP=10, FN=20, TN=130 (total 200). Accuracy = 170/200 = 0.85. Precision = 40/50 = 0.80. Recall = 40/60 = 0.667. F1 = 0.727. Specificity = 130/140 = 0.929.
ROC curve: TPR against FPR (= 1 - specificity) as the threshold varies. AUC is the area under it: 1.0 perfect, 0.5 random. AUC equals the probability that a random positive is scored above a random negative.
On imbalanced data accuracy misleads (a model that always says "negative" scores 99% when only 1% are positive). Use precision, recall, F1 or PR-AUC. Raising the threshold increases precision and lowers recall.
Exam pitfall: F1 uses the harmonic mean, which is lower than the arithmetic mean when the two values differ.
Try two questions
Recall is defined as:
- TP / (TP + FN)
- (TP + TN) / total
- TP / (TP + FP)
- TN / (TN + FP)
Show the answer
A. The fraction of actual positives that are found.
For the same matrix the F1 score is approximately:
- 0.67
- 0.80
- 0.85
- 0.73
Show the answer
D. 2*0.8*0.667/(0.8+0.667) = 0.727.