What is the confusion matrix?
Answer
A confusion matrix is a table that summarizes the performance of a classification model by comparing its predicted labels against the actual labels. For binary classification it is a 2×2 table with four cells: true positives (correctly predicted positive), false positives (negative predicted as positive), false negatives (positive predicted as negative), and true negatives (correctly predicted negative). Unlike a single scalar metric, it shows not only how many predictions were wrong but which kinds of errors were made. For multi-class problems, the matrix expands into a larger square table where cell counts the instances of actual class
predicted as class
; off-diagonal clusters reveal which specific classes the model systematically confuses, guiding model refinement or relabeling.
(1) Structure: Rows are actual classes, columns are predicted classes; the diagonal holds all correct predictions.
(2) Binary Case: The four cells TP/FP/FN/TN feed every classification metric: accuracy, precision, recall, F1.
(3) Multi-Class Case: An matrix whose off-diagonal hotspots expose systematic class confusions.
| Actual \ Predicted | Predicted Positive | Predicted Negative |
|---|---|---|
| Actual Positive | True Positives (TP): correct positive | False Negatives (FN): missed positive |
| Actual Negative | False Positives (FP): false alarm | True Negatives (TN): correct negative |
Mathematical Formulation:
Where:
is the count in row
, column
of the confusion matrix.
is the true label of sample
,
its predicted label, and
indexes the
samples.
is the indicator function: 1 when the condition holds, 0 otherwise.
is the row-normalized version: row
then shows the per-class recall distribution, which reads better under class imbalance.

Figure 1: A 3-class example: strong diagonal means healthy classification; the bright off-diagonal cell shows the model systematically confuses class 1 with class 2.











