Blog › Machine Learning Explained
Learning how to read a confusion matrix starts with one email at a time. Suppose your spam filter sends a school assignment reminder to the spam folder but lets a junk promotion into your inbox. Both predictions are wrong, but they are wrong in opposite directions. A confusion matrix gives each kind of mistake its own cell, so you can see what an overall score leaves out.
A confusion matrix compares the label a model predicted with the label used as the correct answer. In this example, a reviewer has already labeled each email as either spam or not spam. We call that the actual label. The prediction is what the filter decides, whether or not it agrees with the reviewer. The messages below are made up for practice.
| Actual label | Filter prediction | |
|---|---|---|
| Junk prize promotion | Spam | Spam |
| Unsolicited bulk ad | Spam | Spam |
| Second junk promotion | Spam | Not spam |
| School assignment reminder | Not spam | Spam |
| Library receipt | Not spam | Not spam |
| Club meeting update | Not spam | Not spam |
| Reply from a teacher | Not spam | Not spam |
| Requested event confirmation | Not spam | Not spam |
We will treat spam as the positive class. Positive does not mean good. It means the class we are looking for. Here, a positive prediction is the filter saying “spam,” and a negative prediction is the filter saying “not spam.” Keep that choice fixed while you count. If someone instead defines “not spam” as positive, the same blocked reminder gets a different error name even though nothing about the prediction changed.
Put actual labels down the left and predicted labels across the top. With two possible actual labels and two possible predictions, there are four possible pairs. Start all four cells at zero. For each email, find its actual row and its predicted column, then add one where they meet. For the school assignment reminder, go to the actual not spam row and the predicted spam column.
| Actual label | Predicted spam | Predicted not spam |
|---|---|---|
| Actual spam | 2 true positives | 1 false negative |
| Actual not spam | 1 false positive | 4 true negatives |
Check your count in two directions. The row totals are 3 actual spam emails and 5 actual not spam emails. The column totals are 3 spam predictions and 5 not spam predictions. All four cells add up to 8 because each email belongs in exactly one cell. The matching labels sit on the diagonal in this table: actual spam matches predicted spam, and actual not spam matches predicted not spam.
Other tables may put predicted labels on the rows or list not spam first. Read the labels on both axes before using a cell. Never assume a false positive is in a particular corner. When showing your own work, write both axis labels and name the positive class, so someone else can check your counts without guessing your setup. The IMLC explainer on overfitting covers a separate evaluation issue: why results on new data can differ from results on training data.
Read the second word first. Positive or negative tells you what the model predicted. True or false tells you whether that prediction was right. Use the blocked reminder and the missed promotion to test that rule:
The same naming rule explains the correct predictions. The filter caught two spam emails, giving two true positives. It left four legitimate emails out of the spam folder, giving four true negatives. If you forget a name, say the prediction out loud first, then compare it with the actual label. That works even when the table uses a different layout.
The filter made 6 correct predictions out of 8, so its accuracy on this set is 75%. That number tells you how often the filter was right, not which mistake it made. Imagine a second filter that misses no spam but flags two legitimate emails. It also gets 6 out of 8 right. One filter misses a junk promotion and blocks a reminder; the other catches every spam message but blocks more legitimate mail.
To find the share of spam the first filter caught, look only at the actual spam row: 2 out of 3. That share is called recall. To find the share of flagged emails that really were spam, look only at the predicted spam column: 2 out of 3. That share is called precision. The numbers happen to match here, but the groups are different. One starts with all the real spam; the other starts with all the filter's spam predictions. Google's classification guide shows how these measures are calculated.
Try this without rebuilding the table: the filter changes its prediction for the school assignment reminder from spam to not spam. The actual label stays the same. Which two cells change, and what happens to the number of missed spam messages?
Stay in the actual not spam row. Move one count from predicted spam to predicted not spam. False positives drop from 1 to 0, and true negatives rise from 4 to 5. The false negative count stays at 1 because no actual spam email changed predictions. Now try changing the missed junk promotion to predicted spam. Write down the old and new cells before checking the column totals. For a different kind of model to practice evaluating, browse the Machine Learning Explained articles.
Does positive always mean spam?
No. Positive is whichever class you choose to look for. In this example, that class is spam.
Do the rows always show actual labels?
No. Some tables put actual labels in the columns. Read both axis labels before naming an error.
Which error sends a real email to spam?
It's a false positive when spam is the positive class. The filter predicted spam, but the email was not spam.
About the International Machine Learning Competition: an online machine learning competition for high school students from around the world. Qualification Round 2026: submissions are open until Sunday, 13 December 2026. How the rounds work