Lesson 4.7 · 10 min read · about 55 min to master at a very slow pace
Accuracy, Precision, Recall and Specificity
Every metric you can compute from a confusion matrix, what question each one answers, a full worked example, and why accuracy can be dangerously misleading.
The metrics
| Metric | Question it answers | Denominator |
|---|---|---|
| Sensitivity / recall | Of the actual positives, what fraction did we catch? | Actual positives |
| Specificity | Of the actual negatives, what fraction did we correctly clear? | Actual negatives |
| Precision | Of the cases we flagged, what fraction were truly positive? | Predicted positives |
| Accuracy | What fraction of all predictions were right? | Everything |
Smoke alarm
Sensitivity: when there's a fire, how often does the alarm ring? Specificity: when there's no fire, how often does it stay quiet? Precision: when the alarm rings, how often is there really a fire? A hair-trigger alarm has high sensitivity and low specificity; a sleepy one the reverse.
Worked example: all metrics from one table
: TP = 40, FN = 10, FP = 30, TN = 920.
- Accuracy
- Sensitivity
- Specificity ; FPR
- Precision
Baseline: predicting "negative" for everyone gives accuracy with sensitivity 0. Our 0.96 barely beats it. Precision (0.57) is much lower than sensitivity or specificity here, because positives are rare.
Prevalence matters for precision
Sensitivity and specificity condition on the actual class, so they don't depend on how common positives are. Precision conditions on the predicted class, so it does.
The rare-disease surprise
Prevalence 1%, sensitivity 90%, specificity 90%, 1,000 people. Sick: 10, of whom 9 test positive. Healthy: 990, of whom 99 test positive (10%). Total positives 108, of which only 9 are sick: precision = 9/108 = 8.3%. A "90% accurate" test is wrong more than 9 times out of 10 when it says positive.
Accuracy hides rare classes
A fraud model with 99.5% accuracy on data with 0.5% fraud may simply predict "not fraud" for everything. Always compare with the majority-class baseline and report class-specific metrics.
Cheatsheet
Sensitivity / recall / TPR
Specificity / TNR
Precision / PPV
Accuracy & F1
High accuracy, rare class
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.