liveBook · Manning

Precision

As explained in Grokking Machine Learning

A classification metric measuring the proportion of examples predicted as positive that are actually positive.

If a spam filter marks an email as spam, how often is it right? Precision answers that question. It measures the proportion of predicted positives that really are positive. For a spam filter, a false positive is an ordinary email incorrectly marked as spam, so precision matters when that mistake is costly. section 7.2 section 7.4

Precision = TP / (TP + FP). A true positive (TP) is correctly predicted as positive; a false positive (FP) is incorrectly predicted as positive. The denominator counts everything predicted positive, not every example in the dataset. You can find both counts in a confusion matrix. section 7.2 section 13.4

Table 7.4 The confusion matrix of our first spam model (view table figure)

Spam model 1

Predicted spam

Predicted ham

Spam

30 (true positives)

10 (false negatives)

Ham

5 (false positives)

55 (true negatives)

In this spam-filter confusion matrix, look down the predicted-spam column: 30 emails are true positives and 5 are false positives. section 7.2

Compare two spam filters

The first filter’s precision is 30 / (30 + 5), or about 86%. A second filter catches more spam—35 rather than 30 emails—but also flags 10 ordinary emails rather than 5. Its precision is 35 / (35 + 10), or about 78%. Catching more positives does not necessarily make positive predictions more trustworthy. section 7.2

Precision differs from recall: precision asks whether predicted positives are correct, while recall asks how many actual positives were found. Recall falls with false negatives; precision falls with false positives. Accuracy counts overall correct predictions and can hide important errors when the classes are unbalanced. An F1-score combines precision and recall. section 7.0 section 7.4

Try it with a recommendation system: decide what counts as a positive recommendation, count its true and false positives, and calculate precision. Then ask whether false positives or false negatives would be worse for its user before choosing which metric to emphasize. section 7.5

How Grokking Machine Learning covers it

How deep it goes
Defines precision with a formula and confusion-matrix counts, then compares concrete classification errors rather than model-training internals.
Examples
Uses spam-filter and medical-diagnosis counts, plus exercises about video and movie recommendations.
What it assumes
Introduces true positives and false positives using familiar classifications before applying their counts in the precision formula.
What you can do after
Practice/perform precision calculations from classification counts and judge when false positives warrant emphasis.
How it connects
Connects precision to false positives, confusion matrices, accuracy, recall, and F1-score.

Also explained in

Compare how 20 books explain precision →

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.