Back to Classic ML Mind Map
中文·English
📊 Classic MLID: confusion-matrix

Confusion Matrix

混淆矩阵
🎯Core Definition
the fundamental counting table for binary classification, splitting samples into 4 cells by “true label × predicted label”: TP (predicted positive, actually positive), FP (predicted positive, actually negative — Type I error), FN (predicted negative, actually positive — Type II error), TN (predicted negative, actually negative), with total N=TP+FP+FN+TNN = TP + FP + FN + TN. Accuracy Acc=TP+TNNAcc = \frac{TP + TN}{N} is the only metric determined solely by the diagonal. Numerical example: 100 samples with 95 negatives and 5 positives; the model predicts everything as negative, giving TP=0,FP=0,FN=5,TN=95TP=0, FP=0, FN=5, TN=95 and Acc=95/100=95%Acc = 95/100 = 95\% — it looks excellent, yet not a single positive is found (recall = 0). This is the accuracy trap.
💡Use Cases
the starting point of every classification evaluation; all derived metrics (Precision/Recall/F1, specificity, ROC) are read off these 4 cells; for multiclass it generalizes to an N×NN \times N matrix (diagonal = correct predictions), from which macro/micro/weighted averaging is derived.
Key Problems Solved
accuracy is kidnapped by the majority class on imbalanced data (a model that always predicts negative still scores 99% for a 1% prevalence disease), and it is blind to the asymmetric costs of FP vs FN; the confusion matrix exposes both error types and their scale. Macro averaging weights each class equally, MacroP=1Cc=1CPcMacro\,P = \frac{1}{C}\sum_{c=1}^{C}P_c, so rare classes count as much as common ones; micro averaging pools all samples first, MicroP=cTPcc(TPc+FPc)Micro\,P = \frac{\sum_c TP_c}{\sum_c (TP_c + FP_c)}, and is dominated by the largest class — choose macro when classes are severely imbalanced and the rare class matters, micro when class sizes are balanced or only overall performance matters.
🎯5 High-Frequency Exam Points
1
Hand computation: given TP=40,FP=10,FN=20,TN=30TP=40, FP=10, FN=20, TN=30, compute accuracy, precision, recall and F1.
2
Why is a model that always predicts negative, at 99% accuracy for a 1% prevalence disease, useless? Which cell gets sacrificed?
3
Difference between Type I (FP) and Type II (FN) errors; which cell is false-blocking vs missing spam?
4
How macro vs micro averaging are computed and differ; why choose macro when classes are severely imbalanced (e.g. 1000:1)?
5
How to represent and read a multiclass confusion matrix (diagonal, row-normalized, weighted average)?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Confusion Matrix"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardLinear-Chain CRFNext CardPrecision, Recall & F1

🔗 More Classic ML Knowledge Cards

AdaBoost DerivationBagging & Random ForestBaum-Welch (HMM EM)GBDT Negative Gradient