Precision and Recall: The 2 Metrics Accuracy Hides

Precision and recall are the two metrics that reveal what accuracy hides. Whenever your classes are imbalanced β€” fraud, disease, spam, defect detection β€” these two numbers, not raw accuracy, tell you whether a model is actually useful. They are also the classic trade-off in machine learning: push one up and the other tends to fall.

precision and recall trade-off chart

πŸ“Œ
In one line. Precision = how much to trust a positive prediction. Recall = how many real positives you actually caught. Both come straight from the confusion matrix.

Where precision and recall come from

Both are simple ratios of the cells in a confusion matrix β€” the table of True Positives (TP), False Positives (FP), True Negatives (TN), and False Negatives (FN). If you have not met that table yet, read the confusion matrix guide first; everything below builds on it.

Precision = TP / (TP + FP)  β€’  Recall = TP / (TP + FN)

What is precision?

Precision answers: “Of everything the model flagged as positive, how much really was positive?” It measures the trustworthiness of a positive prediction. A spam filter with high precision rarely dumps a real email into the spam folder β€” when it says “spam,” you can believe it. Precision is hurt by false positives (false alarms).

What is recall?

Recall β€” also called sensitivity or the true positive rate β€” answers: “Of all the real positives, how many did the model actually catch?” It measures coverage. A cancer-screening model with high recall misses very few sick patients. Recall is hurt by false negatives (misses).

A concrete precision and recall example

Return to a disease test on 100 patients where 20 are truly sick. The model produces TP = 18, FN = 2, FP = 5, TN = 75:

78%Precision
90%Recall
93%Accuracy (hides it)
84%F1 Score

Precision = 18 / (18 + 5) = 78% β€” when it says “sick,” it is right 78% of the time. Recall = 18 / (18 + 2) = 90% β€” it caught 90% of the patients who were actually sick. The raw accuracy of 93% told you nothing about the 2 missed patients or 5 false alarms.

The precision–recall trade-off

Most classifiers output a probability, and you convert it to a label using a threshold (often 0.5). Move that threshold and you move both metrics in opposite directions:

  • Lower the threshold β†’ the model predicts “positive” more freely β†’ recall rises (fewer misses) but precision falls (more false alarms).
  • Raise the threshold β†’ the model is more cautious β†’ precision rises but recall falls (more misses).
πŸ’‘
Which to prioritise? Favour recall when a miss is dangerous (cancer, fraud, security, predictive maintenance). Favour precision when a false alarm is expensive or annoying (spam filtering, content removal, costly actions).

Combining them: the F1 score

When you need a single number that balances both, use the F1 score β€” the harmonic mean of precision and recall. The harmonic mean punishes imbalance, so a model can only score a high F1 if both are high. For our example, F1 = 2 × (0.78 × 0.90) / (0.78 + 0.90) ≈ 0.84. See the Wikipedia precision and recall article for the formal definitions.

Computing them in Python

from sklearn.metrics import precision_score, recall_score

y_true = [1, 0, 1, 1, 0, 1, 0, 0]
y_pred = [1, 0, 1, 0, 0, 1, 1, 0]

print("Precision:", precision_score(y_true, y_pred))
print("Recall:   ", recall_score(y_true, y_pred))
🚫
Common pitfalls. Never report one without the other (100% precision on a single confident prediction can hide terrible recall); don’t ignore the threshold (tuning it often beats changing the model); and don’t bother on balanced data where accuracy is fine.

Frequently asked questions

Is recall the same as sensitivity?
Yes. Recall, sensitivity, and true positive rate all refer to TP / (TP + FN).
Can precision and recall both be high?
Yes, on an easy, well-separated problem. The trade-off bites when classes overlap β€” then improving one usually costs the other.
What is a good precision or recall value?
There is no fixed threshold; it depends on the base rate and the cost of errors. Compare precision and recall against a sensible baseline and the business cost of each mistake.
Do I always need both precision and recall?
On imbalanced problems, yes β€” report precision and recall together (and often F1), because either number alone can flatter a weak model. On balanced data with equal error costs, accuracy is usually enough.

Related guides

Scroll to Top