Confusion Matrix, Precision & Recall
Machine Learning · Beginner
Definition
A confusion matrix counts TP, FP, FN and TN; precision and recall are computed from it.
Accuracy alone misleads on imbalanced data.
Diagram
Flowchart
Example: Numerical
tp, fp, fn = 40, 10, 20
p, r = tp / (tp + fp), tp / (tp + fn)
print(p, round(r, 3), round(2 * p * r / (p + r), 3))Output: 0.8 0.667 0.727
Key points
- High recall matters for disease detection
- High precision matters for spam filtering
Interview questions
When prefer recall?
When missing a positive is costly, such as cancer screening.