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".

Not startedJump to quiz

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 positivePredicted negative
Actual positiveTP true positive (a hit)FN false negative (a miss)
Actual negativeFP 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:

PatientPredictedActualCell
A0.92++TP
B0.71+−FP
C0.55++TP
D0.40−+FN
E0.15−−TN
F0.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

Rows actual, columns predicted. TP hit · FN miss · FP false alarm · TN. FP = Type I, FN = Type II.

See every cheatsheet by category →

Check your understanding

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

Q1conceptA fraud model flags a legitimate transaction as fraud. Which cell of the confusion matrix is that?
Q2conceptA screening test reports "no disease" for a patient who has the disease. Which cell is that?
Q3calculateAt threshold 0.5, four cases have (score, actual): (0.8, +), (0.6, −), (0.3, +), (0.2, −). What are TP, FP, FN and TN?
Q4applyFor an email spam filter, which error is usually worse?
Q5conceptIn hypothesis-testing language, a false positive is a...