What Is a Confusion Matrix?
A confusion matrix is a table that summarizes how a classification model performed by laying out its predictions against the actual labels. For a binary problem it is a 2x2 grid counting true positives, false positives, true negatives, and false negatives, which together reveal not just how often the model was right but what kinds of mistakes it made. Almost every classification metric, including accuracy, precision, and recall, is computed from these four numbers.
How to read a 2x2 confusion matrix
The rows typically represent the actual class and the columns the predicted class (conventions vary, so always check the labels). The diagonal holds correct predictions, and everything off the diagonal is an error. In binary terms, a true positive is a positive correctly predicted positive, a false positive is a negative wrongly predicted positive (a false alarm), a false negative is a positive wrongly predicted negative (a miss), and a true negative is a negative correctly predicted negative.
| Predicted positive | Predicted negative | |
|---|---|---|
| Actual positive | True positive (TP) | False negative (FN) |
| Actual negative | False positive (FP) | True negative (TN) |
Metrics you can derive from it
Because the matrix holds the raw counts, you can compute the standard metrics directly from it.
- Accuracy = (TP + TN) / total predictions.
- Precision = TP / (TP + FP), the reliability of positive predictions.
- Recall (sensitivity) = TP / (TP + FN), the share of real positives caught.
- Specificity = TN / (TN + FP), the share of real negatives correctly identified.
- F1 = the harmonic mean of precision and recall.
Multiclass confusion matrices
For more than two classes, the confusion matrix becomes an N by N grid where cell (i, j) counts how many items of true class i were predicted as class j. The diagonal is correct predictions, and scanning a row shows which other classes a given class is most often confused with, which is invaluable for diagnosing, say, a model that keeps mixing up two visually similar categories. Per-class precision and recall are then computed by treating each class as the positive one in turn.
Common ways people misread it
The frequent mistakes are confusing the axes (predicted vs actual are sometimes swapped between tools) and judging an imbalanced problem by the diagonal alone. A model can have a large true-negative count that dominates the matrix while barely catching the rare positive class, so always look at the off-diagonal cells and the per-class metrics, not just the totals. In binary terms, a false positive is a Type I error and a false negative is a Type II error.
How TensorTurn uses the confusion matrix
TensorTurn shows the full confusion matrix for every classification run, alongside precision, recall, F1, and accuracy, so you can see exactly which classes the model confuses rather than trusting one aggregate score. Paired with its automated dataset health checks, which flag likely-mislabeled examples, the confusion matrix becomes a practical tool for deciding whether the next fix belongs in the data or the model.
Frequently asked questions
What is the difference between a confusion matrix and accuracy?
Accuracy is a single number summarizing overall correctness. The confusion matrix is the full breakdown of correct and incorrect predictions per class, from which accuracy and many other metrics are computed. The matrix shows what accuracy hides, especially the types of errors.
How do you read a confusion matrix?
Check which axis is actual and which is predicted, then read the diagonal as correct predictions and the off-diagonal cells as errors. In binary problems the four cells are true positive, false positive, false negative, and true negative.
What are Type I and Type II errors?
A Type I error is a false positive, where a negative case is wrongly flagged as positive. A Type II error is a false negative, where a real positive is missed. Both appear as off-diagonal cells in the confusion matrix.
Does a confusion matrix work for more than two classes?
Yes. For N classes it becomes an N by N table, with correct predictions on the diagonal and confusions between specific class pairs shown off the diagonal.