Build a confusion matrix from eight labels

Type each count alongside the label that gives it meaning. · 165 words

Imagine an AI labels 35 wildlife photos from eight classes: cat, dog, bird, fox, horse, rabbit, sheep, and cow. A confusion matrix uses rows for the true class and columns for the predicted class. With the label order just given, the rows of counts are: cat (4,1,0,0,0,0,0,0); dog (1,3,0,0,0,1,0,0); bird (0,0,4,0,0,0,0,0); fox (0,0,0,3,1,0,0,0); horse (0,0,0,0,4,0,0,0); rabbit (0,0,0,0,0,4,0,1); sheep (0,0,0,0,0,0,3,1); cow (0,0,0,0,0,0,1,3). Each entry counts photos with that true and predicted pair.

The diagonal contains correct predictions: 4 + 3 + 4 + 3 + 4 + 4 + 3 + 3 = 28. Since there are 35 photos, accuracy is 28/35 = 80 percent. Off-diagonal cells are errors. The cat row and dog column contains 1, meaning one true cat was predicted as a dog. The dog row and cat column also contains 1, showing the reverse mistake. All off-diagonal cells together contain 7 errors, matching 35 photos minus 28 correct ones. This matrix reveals specific label confusions that one overall accuracy number would hide.

Check your recall

Which cell records the photo that was truly a cat but predicted as a dog, and what does that cell mean?

Check your answer

It is the cell in the cat row and dog column, with a count of 1. It records one cat mislabeled as a dog: a false positive for dog and a false negative for cat.

Sources and credits

Original KeyTouch lesson. Background reading · Google · Classification metrics.