Back to Study Material Machine Learning

Confusion matrix

A confusion matrix is a table that breaks down a classifier's predictions into four categories, giving a detailed view of exactly where the model is gettin...

Confusion matrix

A Complete Picture of Classifier Performance

A confusion matrix is a table that breaks down a classifier's predictions into four categories, giving a detailed view of exactly where the model is getting things right and wrong. For a binary classification problem it is a two-by-two grid whose cells represent true positives, true negatives, false positives, and false negatives.

A true positive is a positive example the model correctly identified as positive. A true negative is a negative example correctly identified as negative. A false positive is a negative example incorrectly labelled as positive — also called a Type I error or false alarm. A false negative is a positive example incorrectly labelled as negative — also called a Type II error or a miss.

The confusion matrix provides the raw counts from which most classification metrics are derived. Accuracy is the sum of correct predictions divided by all predictions. Precision is the proportion of predicted positives that are actually positive. Recall is the proportion of actual positives that the model correctly identified. The F1 score is the harmonic mean of precision and recall, useful when both matter and classes are imbalanced.

Multi-class confusion matrices extend the concept to k categories. Each row represents the actual class and each column the predicted class. The diagonal contains correct predictions; off-diagonal cells reveal which classes the model confuses with each other — often more informative than a single accuracy number.

A concrete example: a disease screening test applied to 1,000 people. 50 have the disease. The model detects 40 of them (true positives) but misses 10 (false negatives) and incorrectly flags 30 healthy people (false positives). The confusion matrix makes these tradeoffs explicit and visible at a glance.

Exam tip: be able to draw a confusion matrix from scratch and derive precision, recall, and F1 from its four cells. This is a staple interview question.