liveBook · Manning

Confusion matrix

As explained in Grokking Machine Learning

A tabular representation of classification outcomes divided into true-positive, true-negative, false-positive, and false-negative counts.

A confusion matrix counts how often a classifier predicts each class correctly or mistakes it for another. For binary classification, its rows show the true labels and its columns show the predicted labels. section 7.2

For two classes, the four counts are:

  • True positive: a positive case predicted positive; true negative: a negative case predicted negative. section 7.2
  • False positive: a negative case predicted positive; false negative: a positive case predicted negative. section 7.2
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. (view table figure)

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

Read across each row to compare a true class with the predicted classes. Correct predictions lie on the diagonal; misclassifications lie off it. section 7.2

A medical diagnosis

If a model labels every patient healthy, it can make few errors overall yet miss every sick patient. Its matrix shows 10 false negatives and zero false positives, making the error pattern visible. section 7.2

How Grokking Machine Learning covers it

How deep it goes
Defines binary matrix layout and error counts, then extends the layout to multiclass classification.
Examples
Uses medical diagnosis, spam detection, and animal-image classes to illustrate classification outcomes.
What you can do after
Evaluate classification models by counting correct predictions and distinguishing false positives from false negatives.
How it connects
Connects classification errors to accuracy, precision, recall, sensitivity, specificity, and F-score.

Also explained in

Compare how 14 books explain confusion matrix →

Related concepts

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