Evaluation & Data Intermediate

Confusion Matrix

A table that sorts right and wrong outcomes into four boxes

Key points
  • A confusion matrix is a table that sorts every right and wrong outcome into four boxes. It lays the whole judgment record out on one page.
  • The four boxes are: caught correctly, flagged for no reason, missed entirely, and quietly passed over.
  • Accuracy, precision, and recall all come out of this table's boxes. The table comes first, the measures come after.
  • It shows how something went wrong, which a single number can't, and that tells you what to fix.
  • With three or more categories the table grows, and it reveals which category gets mistaken for which.
Contents

1The analogy

A fire alarm hangs in a building's hallway. A year later, the maintenance log shows two facts side by side for every day: whether a fire actually broke out, and whether the alarm went off.

Lay those two facts out as rows and columns and you get four boxes: days with a fire where the alarm also went off, days with no fire where it went off anyway, days with a fire where it stayed silent, and quiet days where nothing happened at all.

Drop a year's worth of days into these four boxes, one at a time, and the alarm's report card is complete. Each box fills up differently, and the shape of that filling shows exactly how this alarm behaves. A bloated false-alarm box means it's too jumpy; even one entry in the silent-fire box is a disaster.

This four-box table is the confusion matrix.

2In detail

Each of the four boxes has a name

Each spot where a row and column meet has a fixed name. The box where something you were looking for got correctly caught is a true positive; where something that wasn't there got wrongly flagged is a false positive. Missing something real is a false negative; correctly passing over something that wasn't there is a true negative.

The names sound complicated, but the rule is simple. True or false says whether the judgment was correct; positive or negative says whether it flagged something or not. A false alarm is a false positive; a missed fire is a false negative.

Every measure comes out of this table

Accuracy adds up the two correct boxes and divides by everything. Precision looks only at the two boxes where the alarm went off, and asks what share of those were a real fire. Recall looks only at the two boxes where a fire actually happened, and asks what share of those set off the alarm.

They all come from the same table, only which two boxes get paired up differs. So when the names get confusing, drawing the table first and tracing which row sits underneath usually clears it up fast.

Handed a single measure, the other boxes can't be reconstructed. Handed the table, every measure can be built directly. That's why asking for the table instead of a bare number, when someone hands over evaluation results, is worth doing.

The two mistakes carry different weight

The real reason to look at the table is to separate the two wrong boxes. A false alarm ends the moment people step back inside. A missed fire can't be undone.

That difference in weight only shows up once you look at the table. A score condensed into one number counts both mistakes as one wrong answer apiece. Deciding which box you're willing to let grow, and which one needs to shrink, is the actual decision made on the ground.

Tighten or loosen the judging threshold and the numbers shift between the two boxes. Set it more sensitive and the false-alarm box swells while the missed box shrinks; set it duller and the opposite happens. Lay two tables side by side and which direction an adjustment pushed becomes obvious at a glance.

With more categories, the table grows

With three categories to sort, the table becomes three rows by three columns; with ten, ten by ten. The boxes on the diagonal are where it got things right; anything off the diagonal is somewhere it got confused.

In a big table, look for which box is unusually thick. Two similar-looking categories often get mixed up with each other, and that pairing piles up in one box that stands out immediately. This is exactly how you decide which category needs more training data.

It reads even better as shading instead of raw counts. When categories have very different amounts of data, comparing raw numbers is hard. Scale each row so it sums to the same total and read the darkness of the shade instead, and which row is unusually pale jumps right out.

3More precisely

A confusion matrix counts cases across two axes: the actual value and the judged value. Which one goes on the horizontal isn't fixed by any rule, so some tools put the actual value in the rows and others put it in the columns. Not checking the axis labels first is a common way to read precision and recall backwards.

Boxes sometimes get converted from raw counts into a share of each row's total, instead of staying as raw counts. When one category has far more data than another, a table built from raw counts gets swallowed by the bigger one. The two versions can leave quite different impressions of the same result, so it's worth checking whether a table handed over is counts or shares.

The analogy breaks in one place. A fire alarm's log carries an order, the dates, but a confusion matrix throws order away and keeps only the counts. So it can't tell you whether mistakes clustered in a particular stretch of time, or only happened under specific conditions. Seeing that takes pulling the wrong cases out and looking at them one by one.

4Try it yourself

5Common misconceptions

  • It's easy to think a confusion matrix is some difficult calculation, but actually it's just a table that sorts judgment results into four boxes, the measures come out of it, not the other way around.

  • It's easy to assume all four boxes carry equal weight, but actually a false alarm and a missed case cause completely different amounts of damage, and deciding which to shrink is the real choice.

  • It's easy to think a big number on the diagonal always means a good table, but actually when one category vastly outnumbers the rest, a single fat diagonal box can look that way on its own, reading it by row share tells the real story.

7One-line summary

In shortA confusion matrix sorts every right and wrong outcome into four boxes, and accuracy, precision, and recall are all just numbers built by pairing up its cells.

Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02