Confusion matrix

A confusion matrix is a table that counts a model's predictions against the true labels, with one row per actual class and one column per predicted class, so correct answers sit on the diagonal and every mix-up sits off it.

Metrics

Reading an example

A toy classifier sorts 100 vehicle images into three classes. Rows are the true class, columns the prediction:

Actual \ PredictedCarTruckBus
Car (50)4541
Truck (30)6222
Bus (20)0317

Accuracy is the diagonal over the total: (45 + 22 + 17) ÷ 100 = 0.84. The off-diagonal cells tell more: trucks are called cars six times, while buses are almost never called cars. Recall for a class is its diagonal cell over its row; precision is the diagonal cell over its column.

The two-class case

With one positive class the matrix shrinks to four cells: true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN). Precision and recall and the F1 score are all built from these counts.

Object detection needs a background class

A detector can also find nothing, or find something where there is nothing. Detection matrices add a background row and column: a missed object lands in the background column of its class row, and a false detection lands in the background row. Which cell a prediction falls into depends on the IoU threshold used for matching and on the confidence threshold, so a matrix is only comparable to another built with the same two settings.

Mistakes when reading one

  • Swapped axes: libraries differ on whether rows are actual or predicted. Check the labels before drawing conclusions.
  • Raw counts on imbalanced data: a common class dominates the colors. Normalize each row to see per-class recall.
  • Blaming the model for a cell that is really a labeling error in the ground truth.

In Supervisely

Every evaluation report includes a confusion matrix and a list of frequently confused classes. A cell opens the images behind it, with ground truth and predictions side by side, and one more click opens an image in the labeling tool to correct a label that was wrong.

Frequently asked questions.

How do you read a confusion matrix?

Each row is an actual class and each column a predicted class, so correct answers sit on the diagonal and every mix-up sits off it, in the row of the true class and the column of the class it was taken for.

Does a confusion matrix work for object detection?

Yes, with a background row and column: a missed object lands in the background column of its class row, and a false detection lands in the background row. The result depends on the IoU and confidence thresholds used for matching.