What is a confusion matrix for a binary classifier, and what do its four cells mean? A spam filter checks 100 emails, 20 of which are spam. It flags 18 emails as spam, and 15 of those really are spam. What goes in each cell?
ML systems and evaluation, Classification metrics
Level L1 Beginner. Length Short. Nature Th+Mat Both.
What's being asked
Whether you can sort every prediction into one of four boxes, which is the starting point for accuracy, precision and recall.
Key idea
A confusion matrix is a 2×2 table that counts predictions by their true class and their predicted class. The four cells are true positives (TP: flagged and really positive), false positives (FP: flagged but really negative), false negatives (FN: not flagged but really positive) and true negatives (TN: not flagged and really negative).
Steps
- Draw the table. In scikit-learn (a popular Python library) the rows are the true class and the columns are the predicted class. Some books swap them, so always read the labels.
- Name the cells in words. "True" or "false" says whether the prediction was right; "positive" or "negative" says what the model predicted.
- Fill in the spam numbers. The filter flagged 18 and 15 of them are spam, so and . There are 20 spam emails and 15 were caught, so .
- Everything else is a correctly ignored normal email: . Check: .
- Say why the table helps. It keeps the two kinds of mistake apart: 3 false alarms and 5 missed spam emails. A single accuracy number would mix them together.
Common mistakes
- Swapping FP and FN. A false positive is a false alarm; a false negative is a miss.
- Reading the table with the wrong orientation. Check which side holds the true class before reading off the cells.
- Forgetting the true negatives. They are usually the largest cell, and accuracy counts them.
How long your answer should be
About 2 minutes: the 2×2 table, the four names, then 15, 3, 5 and 77.
Last checked on 4 December 2026.
Read this
Previous in ML systems and evaluation: In plain words, what are precision and recall for a binary classifier? A spam filter flags 10 emails and 8 of them are truly spam, while the inbox holds 16 spam emails in all. What are its precision and recall?
Next in ML systems and evaluation: What is an online A/B test, why are users split at random between the two versions, and what does 'statistically significant' roughly mean? If version A gets 50 clicks from 1000 users and B gets 60 from 1000, can you already say B is better?