Lesson 4.6 · 7 min read · about 45 min to master at a very slow pace
The Confusion Matrix
Once you pick a threshold, every prediction is a true positive, false positive, true negative or false negative. How to build the table, read it, and which errors are "misses" and which are "false alarms".
Four outcomes
Fix a threshold and classify every observation. Choose one class as the positive class: the important one (disease present, fraud, alert needed). Each prediction then falls into one of four cells:
| Predicted positive | Predicted negative | |
|---|---|---|
| Actual positive | TP true positive (a hit) | FN false negative (a miss) |
| Actual negative | FP false positive (a false alarm) | TN true negative |
Statisticians also call FP a Type I error and FN a Type II error. Row totals are the actual class sizes (, ); column totals are how many the model flagged.
Check the layout
Some books and software put predictions in rows and actuals in columns. Always read the labels before computing anything.
Building one
Worked example
Six patients, threshold 0.5:
| Patient | Predicted | Actual | Cell | |
|---|---|---|---|---|
| A | 0.92 | + | + | TP |
| B | 0.71 | + | − | FP |
| C | 0.55 | + | + | TP |
| D | 0.40 | − | + | FN |
| E | 0.15 | − | − | TN |
| F | 0.08 | − | − | TN |
So TP = 2, FP = 1, FN = 1, TN = 2.
Which error is worse?
It depends on the decision, never on the maths. In cancer screening, a miss (FN) can be fatal while a false alarm (FP) means an extra test: FNs are worse. In spam filtering, a false alarm hides a real email from you: FPs are worse. This judgement drives the choice of metric (4.7) and threshold (4.9).
Cheatsheet
Confusion matrix
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.