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.

Not startedJump to quiz

The metrics

MetricQuestion it answersDenominator
Sensitivity / recallOf the actual positives, what fraction did we catch?Actual positives
SpecificityOf the actual negatives, what fraction did we correctly clear?Actual negatives
PrecisionOf the cases we flagged, what fraction were truly positive?Predicted positives
AccuracyWhat 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

: share of actual positives caught.

Specificity / TNR

: share of actual negatives cleared. FPR spec.

Precision / PPV

: share of flagged cases truly positive. Depends on prevalence.

Accuracy & F1

Acc . .

High accuracy, rare class

Compare with the majority-class baseline. Report sensitivity, specificity, precision.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateTP = 30, FN = 20, FP = 10, TN = 140. What are the sensitivity and specificity?
Q2calculateSame table (TP = 30, FN = 20, FP = 10, TN = 140). What is the precision?
Q3conceptWhich formula gives specificity?
Q4interpretA test has sensitivity 0.95 and specificity 0.60. In plain words?
Q5calculateA disease affects 1% of people. A test has 90% sensitivity and 90% specificity. Of the people who test positive, roughly what share actually have the disease?