How to Read a Confusion Matrix for a Spam Filter

The first step in learning how to read a confusion matrix is to check the axis labels, not the numbers. In a spam filter test, the top right cell might count legitimate messages sent to the spam folder. In another table, that same position might count spam messages that reached the inbox. The difference is whether the table puts the actual labels on the rows or on the columns.
Start with the email labels
Imagine testing a filter on 100 emails that have already been labeled as spam or not spam. These are the actual labels, the reference answers for the test. The filter gives each message its own label, called the predicted label. In this example, messages predicted to be spam go to the spam folder, and messages predicted to be not spam go to the inbox.
We choose spam as the positive class, the category we want to detect. The negative class is not spam. Positive does not mean good, and negative does not mean bad. Here, a positive prediction just means the filter says, “This is spam.” A confusion matrix counts how many messages fall into each combination of actual and predicted labels.
How to read a confusion matrix one cell at a time
In this table, the rows show what the emails actually are. The columns show what the filter predicted. To read a cell, say its row and column labels together before looking at the count.
| Actual label | Predicted spam | Predicted not spam |
|---|---|---|
| Actually spam | 18 | 2 |
| Actually not spam | 3 | 77 |
- 18 true positives: The emails were spam, and the filter predicted spam. The filter caught them.
- 2 false negatives: The emails were spam, but the filter predicted not spam. They slipped into the inbox.
- 3 false positives: The emails were not spam, but the filter predicted spam. These could be messages you wanted, such as a school announcement.
- 77 true negatives: The emails were not spam, and the filter predicted not spam. They went to the inbox as intended.
If the names sound backward, start with the prediction. A false positive is a positive prediction that was wrong. A false negative is a negative prediction that was wrong. The words true and false tell you whether the prediction matched the actual label. The words positive and negative tell you which prediction the filter made. Google's classification guide uses the same terminology.
Check what changes when the axes swap
Here are the same test results with predictions on the rows and actual labels on the columns. No message changed folders. Only the layout changed.
| Predicted label | Actually spam | Actually not spam |
|---|---|---|
| Predicted spam | 18 | 3 |
| Predicted not spam | 2 | 77 |
The top right cell used to mean “actually spam, predicted not spam.” Now it means “predicted spam, actually not spam.” The top right count goes from 2 missed spam messages to 3 wrongly flagged legitimate messages. If you memorized that the top right cell holds false negatives, you would report the wrong mistake.
The two correct counts, 18 and 77, stay on the main diagonal in both tables because both axes list spam first and not spam second. But a table can list the classes in a different order on one axis. If only the columns in the first table were reversed, the correct counts would sit off the main diagonal. Look for cells where the two class labels match, not cells in a particular position. If a chart does not tell you which axis is which, check the caption or documentation before interpreting it.
Use totals to answer the right question
The filter got 18 + 77 = 95 messages right out of 100, so its accuracy on this test was 95%. That number does not tell you how often the filter missed spam. For that, look only at the messages that were actually spam. There were 18 + 2 = 20 of them, and 2 got through. The filter missed 2 out of 20 spam messages, or 10%.
Now suppose you open the spam folder and want to know what share of the messages there were flagged by mistake. The folder contains all 18 correctly flagged messages and all 3 wrongly flagged messages. That makes 3 out of 21, or about 14%. This is not the same as asking what share of all legitimate messages were wrongly flagged. That question uses 77 + 3 = 80 as the denominator, giving 3 out of 80, or 3.75%. Both calculations start with the same 3 false positives, but they describe different groups of emails.
Practice with a filter that never flags spam
Suppose a second filter sees the same 100 emails but predicts not spam for every one. Before drawing a table, work out which cells must be zero. Since the filter never predicts spam, it has no true positives and no false positives. All 20 spam messages are false negatives, and all 80 legitimate messages are true negatives. It gets 80% of the emails right without catching any spam at all.
Draw that second filter's matrix with predictions on the rows. Then redraw it with actual labels on the rows and check that you can still find the 20 missed messages by reading the labels. For more practice with reading conditions before calculating, see the ICSC training and practice problems or browse the Computer Science Explained articles.
Frequently asked questions
Are the actual labels always on the rows?
No. Some tables put actual labels on the columns. Check both axes before naming any cell.
Is a missed spam message a false positive?
No. If spam is the positive class, missed spam is a false negative because the filter wrongly predicted not spam.
Are correct predictions always on the main diagonal?
Only when both axes list the classes in the same order. A correct prediction is any cell where the actual and predicted class labels match.



