الانتقال إلى المحتوى
Machine Learningتقييم الموديلات· 6 دقائق للقراءة

Precision vs Recall: Choose the Error You Can Afford

They count different mistakes, and moving the threshold trades one for the other. Only a better model raises both.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A comment filter hides posts it scores as abusive. Users complain that normal comments keep disappearing, so a developer raises the threshold from 0.5 to 0.8. Precision jumps from 0.84 to 1.00, and the changelog reads "model improved: precision 100%". Two weeks later the moderators report that far more abuse is getting through. Nothing improved. Recall fell from 0.34 to 0.14: the filter now catches 1 abusive comment in 7.

The common misconception

Many developers treat precision and recall as two names for "how accurate the model is", so raising either one means the model got better. It's easy to see why:

  • They share a numerator: both count the true positives, the cases the model flagged correctly.
  • They're usually printed side by side in the same report, so they look like two readings of the same quantity.
  • When a model really improves, with better features or a better algorithm, both often rise together.

The half-truth: a better model can lift both. But most day-to-day changes to precision or recall come from moving the cutoff, and that never improves the model. It only moves its mistakes from one column to the other.

What actually happens

Every classifier makes two kinds of mistakes: false positives, flagging something that's fine, and false negatives, missing something real. Precision and recall each watch one of them.

Same numerator, different denominators

is true positives divided by everything the model flagged. It answers: when the filter hides a comment, how often is it really abusive? is true positives divided by everything that's really positive. It answers: of all the abusive comments, how many did the filter catch? Precision is blind to misses, and recall is blind to false alarms.

Each one alone is easy to max out

Flag everything and recall is a perfect 1.0, while precision falls to the share of positives in the data, about 10% here. Flag only the single most obvious case and precision can be 1.0 while recall is close to zero. scikit-learn's precision-recall example describes the two ends: high recall with low precision returns most relevant items along with many wrong ones; high precision with low recall returns few relevant items, but most of them are right.

The threshold trades one for the other

A classifier outputs a score, and the decides which scores become flags. Raise it and fewer comments are flagged: fewer false alarms, so precision tends to rise, and more misses, so recall falls. Google's Machine Learning Crash Course says the two often show an inverse relationship, where improving one worsens the other. That's exactly what happened in the comment filter:

Python
from sklearn.datasets import make_classificationfrom sklearn.linear_model import LogisticRegressionfrom sklearn.metrics import precision_scorefrom sklearn.model_selection import train_test_splitX, y = make_classification(n_samples=6000, n_features=10, n_informative=5,                           weights=[0.9], flip_y=0.02, class_sep=0.8,                           random_state=1)  # about 10% abusive commentsX_tr, X_te, y_tr, y_te = train_test_split(X, y, stratify=y, random_state=0)proba = LogisticRegression().fit(X_tr, y_tr).predict_proba(X_te)[:, 1]for cut in (0.5, 0.8):    precision = precision_score(y_te, proba >= cut)    print(f"threshold {cut}: precision {precision:.2f}")# threshold 0.5: precision 0.84# threshold 0.8: precision 1.00# "Precision is up: the model got better"

Read the logistic rows in the second script top to bottom: as the threshold rises, precision climbs from 0.44 to 1.00 and recall drops from 0.58 to 0.14. At 0.8 the filter hides 22 comments, all correctly, and lets most of the abuse through. The "100% precision" was a smaller, safer list, not a smarter model. Recall can't rise when the threshold goes up, because the set of flags only shrinks. Precision usually rises, but the scikit-learn example notes it doesn't have to: it can fluctuate while recall stays the same.

Only a better model raises both

Now compare the models at the same threshold of 0.5. Gradient boosting has higher precision, 0.91 against 0.84, and nearly twice the recall, 0.60 against 0.34. Or compare rows with similar recall: boosting at 0.8 finds 51% of the abuse with a precision of 0.95, while logistic regression at 0.2 finds 58% with 0.44. That's what real improvement looks like: the model ranks abusive comments above normal ones more reliably. A threshold change slides along one model's trade-off; a better model offers a better trade-off.

Choose the error you can afford

Which number to favor depends on what each mistake costs. The Crash Course's guidance: favor recall when false negatives are more expensive than false positives, and precision when it's very important for positive predictions to be right.

SituationCostlier mistakeFavor
Spam filter moving mail to junkHiding a real emailPrecision
Screening for a serious disease, with a follow-up testMissing a sick patientRecall
Review queue with a fixed daily capacityWasting reviewer time on false alarmsPrecision at that queue size
Comment filter that hides postsBoth, at different costsA minimum for one, the best possible other

When you need a single number, F1 is the harmonic mean of the two; the Crash Course notes that when they're far apart, it ends up close to the worse one. scikit-learn's fbeta_score weights them: beta=2 makes recall twice as important as precision, and beta=0.5 does the opposite.

How to apply it in your project

  1. Name both mistakesWrite down what a false positive and a false negative cost in your product: a hidden comment, a missed fraud, an unneeded call.
  2. Report the pairPrint precision, recall and the number of flags together, for every model and every threshold you compare.
  3. Turn costs into a targetSet a minimum for the metric that protects the costlier mistake, or use fbeta_score with a beta that reflects the ratio.
  4. Choose the threshold on validation dataPick the cutoff that meets the target on validation data, then check it once on the test set.
  5. Improve the model to improve bothTo raise precision and recall together, work on features and the model, and compare candidates at the same threshold or across the whole curve.

Key takeaways

  • Precision counts how many flags were right; recall counts how many real cases were found.
  • Moving the threshold trades one for the other: 0.84/0.34 became 1.00/0.14 with the same model.
  • A better model raises both at once: boosting reached 0.91/0.60 at the same threshold.
  • Decide which mistake costs more, set a target, and always report precision and recall together.

📚 المصادر

  1. Classification: Accuracy, recall, precision, and related metrics — Google Machine Learning Crash Course
  2. Precision-Recall — scikit-learn examples
  3. fbeta_score — scikit-learn API Reference

التعليقات (0)