Skip to content
mlmentorship

Precision, recall, and F1

The three metrics every classifier interview asks about. Their definitions, when to optimize which, and the F-beta generalization.

Published · 5 min read ·Core ·Foundation

Summary

For a binary classifier:

  • Precision = . Of the positives I predicted, what fraction are correct?
  • Recall = . Of the actual positives, what fraction did I catch?
  • F1 = . Harmonic mean of the two.

These are the three most-cited classification metrics. Picking the wrong one for your problem is a senior-level mistake; recommending “use precision and recall” without specifying the operating point is a common interview tell.

The four base counts

Predicted positivePredicted negative
Actually positiveTPFN
Actually negativeFPTN

Different metrics weight these differently:

  • Accuracy = . Fraction correct overall; it can hide poor rare-class performance and does not encode unequal error costs.
  • Precision = . Column purity (predicted positive).
  • Recall = . Row purity (actual positive). Also called sensitivity or true positive rate.
  • Specificity = . True negative rate.

When to favor precision vs. recall

Choose based on the relative cost of false positives vs. false negatives:

ScenarioCost of FPCost of FNOptimize
Spam filterUser loses important emailUser sees spamPrecision
Cancer screeningUnnecessary biopsyMissed cancerRecall
Web search top resultWrong page surfacesRight page on page 2Precision
Fraud detectionLegitimate transaction blockedFraud succeedsBoth. Depends on dollar values
Recommendation candidate generationBoring recMissing a perfect recRecall (filter later)

Recall is nondecreasing as a fixed ranking’s threshold falls, but precision can rise, fall, or stay unchanged. For ranked labels [1,0,1], accepting the first two gives precision and recall both . Accepting the third gives precision and recall one: both increase. Compare actual operating points and costs rather than assuming every change exchanges precision for recall. Declare the treatment of zero denominators; the confusion-matrix lesson distinguishes counts from undefined ratios and averaging conventions.

F1 and F-beta

The F1 score balances precision and recall via the harmonic mean. Harmonic mean penalizes imbalance: F1 is low if either P or R is low, even if the other is high.

Learning objective

High precision cannot hide low recall in the harmonic mean

One weak side pulls down the harmonic meanPrecision 0.9 and recall 0.1 produce F1 0.18, not their arithmetic average 0.5.The weaker rate dominates reciprocalcostPrecision 0.9: reciprocal 1.111Recall 0.1: reciprocal 10F1 = 2 / (1/0.9 + 1/0.1) = 0.18Not the arithmetic mean 0.5.
Derivation

Balanced pair

Neither metric hides a weak side.

Precision0.50
Recall0.50
Arithmetic mean0.50
F10.50

2(0.50)(0.50) / (0.50 + 0.50) = 0.50

Imbalanced pair

The same arithmetic mean masks one weak metric.

Precision0.90
Recall0.10
Arithmetic mean0.50
F10.18

2(0.90)(0.10) / (0.90 + 0.10) = 0.18

Read it this way: both pairs average to 0.50 arithmetically, but F1 drops to 0.18 when recall is only 0.10. A high precision score cannot compensate for weak recall (and vice versa).
Check: Why does precision 0.90 fail to compensate for recall 0.10 even though their arithmetic mean is 0.50?
Read it this way: Precision 0.9 and recall 0.1 produce F1 0.18, not their arithmetic average 0.5.
Which reciprocal term dominates when precision is 0.9 but recall is 0.1?

The F-beta generalization weights recall times more than precision:

  • → F1 (equal weight).
  • → F2 (recall weighted 4× more. Favors finding all positives).
  • → F0.5 (precision weighted 4× more. Favors avoiding false positives).

Multi-class

For classes, two averaging strategies:

  • Macro-averaged: compute precision/recall/F1 per class, then average. Treats all classes equally. Penalizes models that ignore minority classes.
  • Micro-averaged: aggregate TP/FP/FN across all classes, then compute. Equivalent to overall accuracy for multi-class. Dominated by majority classes.
  • Weighted: macro-average weighted by class support. Compromise.

For imbalanced multi-class: report macro-F1 to ensure minority classes are evaluated, and per-class precision-recall for diagnosis.

Threshold dependence

Precision and recall are computed at a specific decision threshold (e.g., 0.5 for predicted probability). A single P/R pair represents one operating point on the precision-recall curve. Always know which threshold you used.

For threshold-independent comparison, report:

  • PR-AUC (area under the precision-recall curve).
  • ROC-AUC (separability metric, threshold-free).
  • See ROC, PR, and AUC.

Common pitfalls

  • Reporting accuracy on imbalanced data. A 1% positive class trivially gets 99% accuracy by predicting “negative” always.
  • Reporting F1 alone. F1 is a single number; the precision-recall tradeoff matters.
  • Comparing F1 across datasets with different positive priors. F1 depends on class balance.
  • Treating threshold 0.5 as default. It’s an arbitrary choice; pick from the PR curve at the deployment operating point.
  • Confusing recall with sensitivity (and specificity). Recall = sensitivity = TPR. Specificity is a different quantity (TNR).
  • Macro-F1 on label-skewed data: a model that aces 99 majority-class examples and bombs 1 minority class still gets a poor macro-F1. Sometimes that’s the right signal, sometimes it’s misleading.