Precision and Recall — Definition, Formula & Example
Precision and recall are two scores for a yes/no classifier. Precision asks "When the model says yes, how often is it right?" Recall asks "Of all the real yes cases, how many did the model find?"
For a binary classifier, sort each prediction into one of four outcomes: true positive (TP), false positive (FP), false negative (FN) or true negative (TN). Precision is the proportion of predicted positives that are actual positives, . Recall, also called sensitivity or the true positive rate, is the proportion of actual positives that the classifier predicts as positive, . Neither metric uses TN. Each takes values in , and each is undefined when its denominator is 0.
Key Formula
Where:
- = True positives: actual positives that the model predicted as positive
- = False positives: actual negatives that the model wrongly predicted as positive
- = False negatives: actual positives that the model missed
Worked Example
Problem: A spam filter scans 200 emails. Exactly 50 of them are actually spam. The filter flags 40 emails as spam, and 32 of those flagged emails really are spam. Find the filter's precision and recall.
Step 1: Sort the counts into outcomes. The 32 correctly flagged emails are true positives. The other flagged emails are false positives. The spam emails the filter did not flag are false negatives.
Step 2: Precision divides by everything the filter flagged.
Step 3: Recall divides by all the emails that are actually spam.
Answer: Precision is 0.80, so 80% of the flagged emails are truly spam. Recall is 0.64, so the filter catches 64% of all spam, and 18 spam emails still reach the inbox. Both scores use the same 32 correct flags, but they divide by different totals.
Why It Matters
Accuracy can mislead when one class is rare. A cancer screen that calls every patient healthy may be 99% accurate and still have a recall of 0. In machine learning and data science courses, you tune a model's decision threshold to trade one metric against the other. You can also combine them into the F1 score, which is their harmonic mean.
Common Mistakes
Mistake: Swapping the denominators, so that you divide by the number of actual positives when you compute precision.
Correction: Precision is about the model's predictions, so its denominator is everything predicted positive (TP + FP). Recall is about reality, so its denominator is everything actually positive (TP + FN). Ask yourself what the question conditions on: "given the model said yes" or "given it really is yes."
