All labs

Accuracy Is a Trap: Metrics Under Class Imbalance

Move a threshold, move the prevalence, and watch which performance numbers stay honest and which quietly lie.

Ch 5 5.6
Comparator
Supervised Learning
20 mindifficulty 2/5

Controls

2.0%

Share of positives in the population.

1.600

How far apart the two latent score distributions sit.

0.500

Changes the confusion matrix only — not the ranking.

2000
Random seed

Every result on this page is a deterministic function of the seed and the controls.

Score distributions by true class

The threshold is a vertical cut.

051015202500.200.400.600.801[0, 0.03) n=1775[0.03, 0.07) n=107[0.07, 0.10) n=31[0.10, 0.13) n=15[0.13, 0.17) n=12[0.17, 0.20) n=3[0.20, 0.23) n=5[0.23, 0.27) n=3[0.27, 0.30) n=3[0.30, 0.33) n=1[0.33, 0.37) n=1[0.37, 0.40) n=0[0.40, 0.43) n=1[0.43, 0.47) n=0[0.47, 0.50) n=0[0.50, 0.53) n=0[0.53, 0.57) n=0[0.57, 0.60) n=0[0.60, 0.63) n=1[0.63, 0.67) n=0[0.67, 0.70) n=0[0.70, 0.73) n=0[0.73, 0.77) n=0[0.77, 0.80) n=0[0.80, 0.83) n=0[0.83, 0.87) n=0[0.87, 0.90) n=0[0.90, 0.93) n=0[0.93, 0.97) n=0[0.97, 1) n=0[0, 0.03) n=7[0.03, 0.07) n=3[0.07, 0.10) n=6[0.10, 0.13) n=4[0.13, 0.17) n=2[0.17, 0.20) n=1[0.20, 0.23) n=1[0.23, 0.27) n=2[0.27, 0.30) n=2[0.30, 0.33) n=0[0.33, 0.37) n=5[0.37, 0.40) n=2[0.40, 0.43) n=1[0.43, 0.47) n=0[0.47, 0.50) n=1[0.50, 0.53) n=0[0.53, 0.57) n=0[0.57, 0.60) n=0[0.60, 0.63) n=1[0.63, 0.67) n=2[0.67, 0.70) n=1[0.70, 0.73) n=0[0.73, 0.77) n=0[0.77, 0.80) n=0[0.80, 0.83) n=0[0.83, 0.87) n=1[0.87, 0.90) n=0[0.90, 0.93) n=0[0.93, 0.97) n=0[0.97, 1) n=0tpredicted probabilitydensity
NegativesPositives

ROC

AUC = 0.936 — threshold-free.

00.200.400.600.80100.200.400.600.801false positive ratetrue positive rate

Precision–recall

Average precision = 0.520 — baseline 0.021.

00.200.400.600.80100.200.400.600.801recallprecision

Confusion matrix at the current threshold

Pred +
Pred −
True +
5
37
True −
1
1957
Accuracy
98.10%
always-negative: 97.90%
Balanced accuracy
55.93%
Sensitivity / recall
11.90%
Specificity
99.95%
Precision (PPV)
83.33%
depends on prevalence
F1
0.208
MCC
0.311
robust to imbalance
AUC
0.936
independent of threshold