Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Core concepts

Confusion Matrix

About 3877 characters Updated Nov 30, 2026 29 views AI wiki

A confusion matrix is the basic table for evaluating a classification model: it cross-tabulates each sample's predicted class against its actual class, showing cell by cell what the model "mistook for what". Almost all classification metrics - accuracy, precision, recall, specificity, and F1 score - can be derived from this table, so understanding the confusion matrix is the prerequisite for reading model evaluation.

Core Principles

For a K-class problem, the confusion matrix is a K by K square matrix, with rows usually denoting the actual class and columns the predicted class; the element in row i and column j is the number of samples that "are actually i but were predicted as j". The numbers on the diagonal are correctly predicted samples, and the off-diagonal numbers are errors of various types.

The binary case is the most common and forms a four-cell structure. True positives, TP, and true negatives, TN, sit on the diagonal and represent correct judgments; false positives, FP, are "actually negative but judged positive", commonly called false alarms; false negatives, FN, are "actually positive but judged negative", commonly called misses. All metrics can be composed from these four numbers; for example, accuracy is the sum of the diagonal divided by the total, and specificity is TN / (TN + FP).

The real value of the confusion matrix lies in revealing the distribution of errors. Looking only at accuracy, 90 percent may mean balanced correctness across classes, or it may mean one class is completely wiped out but diluted by the large classes. The matrix exposes this immediately and reveals the specific direction of confusion - for example, in digit recognition the model often reads a four as a nine - and such systematic bias is something a single scalar metric can never convey.

A concrete example: ten-class handwritten digit recognition with 95 percent overall accuracy looks good. But the confusion matrix may show that the digit one is almost always right, while recall for the digit nine is only 60 percent and is mainly misclassified as four. Such information points directly to skewed data collection or insufficient samples for one class, and is the most direct clue for improving the model.

Key Points

Reading the matrix requires distinguishing row normalization from column normalization. With row normalization each row sums to 1, and each cell is "among samples that are actually i, the proportion judged as j", suited to recall; with column normalization each cell is "among samples judged as j, the proportion that are actually i", suited to precision. Many misreadings in analysis come from confusing these two viewpoints.

For multiclass problems a "one-versus-rest" viewpoint can also be extended: treating class i as positive and merging the rest as negative lets a metric set be computed for each class separately, which is the source of the classification reports in common machine-learning libraries, where the precision and recall of each class are computed exactly this way. In object detection the confusion matrix is more complex, because there is also a "background" class and a localization-quality threshold, and an IoU below the threshold is often counted as a background false alarm.

Also pay attention to the scale effect of the matrix. With very few samples, the numbers fluctuate greatly, and a single sample's difference can make precision jump more than ten percentage points, so confidence intervals or results from repeated sampling should be reported alongside rather than a single point estimate.

Common Misconceptions

Treating the confusion matrix as a tool designed only for binary classification, when it applies equally to multiclass problems and is even more diagnostically valuable there. Another misconception is looking only at the diagonal and ignoring off-diagonal patterns, when the latter show the direction for improving the model. Also distinguish the count matrix from the proportion matrix: they convey different information, and reports should state clearly which one is used. Note also that with imbalanced samples the raw count matrix shows a lopsided illusion, and it should be read together with a normalized matrix.

Application Scenarios

Analysis of missed and mistaken diagnoses in medical diagnosis, malware classification, multi-class confusion in sentiment analysis, phoneme-level diagnosis in speech recognition, land-cover classification of remote-sensing imagery, fraud-category identification in credit scoring, and exposure-bias analysis of long-tail categories in recommender systems.