liveBook · Manning

Confusion matrix

As explained in Grokking Statistics

A confusion matrix is a table that cross-tabulates predicted classes against actual classes and counts correct and incorrect classifications.

A confusion matrix is a table that compares predicted classes with actual classes. It separates correct predictions from the two ways a classification can be wrong. section 8.8

Read the four cells as follows:

  • True positive (TP): the system predicts the positive class, and the case is actually positive. section 8.8
  • False positive (FP): the system predicts the positive class, but the case is actually negative. section 8.8
  • True negative (TN): the system predicts the negative class, and the case is actually negative. section 8.8
  • False negative (FN): the system predicts the negative class, but the case is actually positive. section 8.8

The wolf alarm that scores 98%

Imagine an alarm tested across 100 days. It misses one wolf and falsely reports another, while producing 98 true negatives. Accuracy looks impressive, but the zero true positives reveal that it detected no actual wolves. Predicting “no wolf” every day would even reach 99% accuracy. section 8.8

The desirable pattern places counts on the top-left to bottom-right diagonal: true positives and true negatives high, false positives and false negatives near zero. When positive cases are uncommon, class imbalance can make accuracy look strong while hiding poor detection. section 8.8 section 8.9

The matrix also supports precision and recall. Precision asks how often positive predictions are correct; recall asks how many actual positive cases are found. Raising the alarm threshold may improve precision while reducing recall. section 8.9

Inspect the confusion-matrix figure to see actual classes arranged against predicted classes and locate correct versus incorrect outcomes. section 8.8

How Grokking Statistics covers it

How deep it goes
Defines four matrix cells and interprets imbalance, then connects them to precision and recall without covering other negative-focused measures.
Examples
Uses a wolf-detection alarm tested over 100 days and a later evaluation involving more wolves across 500 days.
What it assumes
Assumes binary classification language while defining predicted values, actual values, and the four outcome categories directly.
What you can do after
Evaluate classification results by identifying correct predictions, false alarms, missed cases, and accuracy failures caused by imbalance.
How it connects
Connects accuracy, class imbalance, precision, recall, false positives, false negatives, and classification thresholds.

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 Statistics. The section links point to the parts of the book it draws on.