liveBook · Manning

Confusion matrix

As explained in Grokking Machine Learning, Second Edition

A tabular arrangement of classification outcomes that distinguishes true positives, true negatives, false positives, and false negatives.

A confusion matrix is a table that counts how a classification model’s predictions compare with the true labels. For binary classification, its rows contain true labels and its columns contain predicted labels. section 7.6

The four cells in a binary confusion matrix distinguish correct predictions from two kinds of error:

  • True positive: a positive case predicted as positive. section 7.6
  • True negative: a negative case predicted as negative. section 7.6
  • False positive: a negative case predicted as positive. section 7.6
  • False negative: a positive case predicted as negative. section 7.6

A medical diagnosis example

Suppose a model diagnoses every patient as healthy. Among 1,000 patients, it produces 990 true negatives, 10 false negatives, and no true positives or false positives. The matrix exposes the dangerous pattern: every sick patient is missed, even though the model may appear accurate because most patients are healthy. section 7.6

Table 7.1 The confusion matrix helps us count how many times each class is predicted correctly and how many times each class is confused with a different class. In this matrix, the rows represent the label, and the columns represent the prediction. The elements in the diagonal are classified correctly, and the elements off the diagonal are not.
Person’s condition
Predicted positive
Predicted negative
Positive
Number of true positives
Number of false negatives
Negative
Number of false positives
Number of true negatives

Use the matrix diagram to see how rows represent actual conditions, columns represent predictions, diagonal cells represent correct classifications, and off-diagonal cells represent confusion. section 7.6

How Grokking Machine Learning, Second Edition covers it

How deep it goes
Defines binary and multiclass layouts and connects cells to evaluation metrics, but stops short of implementation details.
Examples
Uses medical diagnosis, spam filtering, recommendations, pedestrian detection, and a multiclass animal classifier.
What it assumes
Assumes classification labels and predictions, while defining the four outcome types through medical examples.
What you can do after
Evaluate classification models by identifying error types and reading metric-relevant counts from the matrix.
How it connects
Connects true positives, true negatives, false positives, false negatives, accuracy, recall, precision, sensitivity, specificity, F-score, and ROC curves.

Also explained in

Compare how 16 books explain confusion matrix →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning, Second Edition. The section links point to the parts of the book it draws on.