Skip to content
ML Visualization

Precision, Recall & F1

Data Prep & Model EvaluationIntermediate~7 min

Precision, Recall & F1Trade off catching positives against being right about them.

Precision asks “when I say positive, am I right?” Recall asks “did I catch all the positives?” They pull against each other, and F1 balances the two.

  • Swept so far
  • Not yet reached
  • No-skill baseline
  • Operating point

Precision, recall and F1.0 against the threshold (click to jump)

  • Precision
  • Recall
  • F1.0
01
100%
Precision
2%
Recall
3%
F1.0

Precision / recall controls

Data
Scenario

Half the cases are positive and both mistakes cost the same — the textbook setting where 0.5 is defensible.

50%
0.60
Model
1.00
1.00

β < 1 favours precision (spam), β > 1 favours recall (screening), β = 1 is plain F1.

Average precision0.941
Expected cost197
Playback
Step 0 / 100
Speed
  1. Strict (t → 1)
  2. Balanced
  3. Permissive (t → 0)

Step 0 of 100 — t = 1.00 — precision 100% (3/3 flagged were right), recall 2% (3/200 positives caught), F1.0 3%

Break it

The idea in plain words

Precision asks “when I say positive, am I right?” Recall asks “did I catch all the positives?” They pull against each other: lower the threshold to catch more (higher recall) and you let in more false alarms (lower precision).

F1 balances the two into one number. On imbalanced data, watch precision collapse even as accuracy looks fine — which is why the confusion matrix underneath matters.

Now, the math

Precision, recall, and their harmonic mean F1:

P=TPTP+FP,R=TPTP+FN,F1=2PRP+RP = \frac{TP}{TP+FP},\quad R = \frac{TP}{TP+FN},\quad F_1 = \frac{2PR}{P+R}
PP
precision — correctness of positive predictions.
RR
recall — coverage of the actual positives.
F1F_1
harmonic mean — high only when both are high.
Show the derivation

The harmonic mean punishes imbalance between P and R far more than an arithmetic mean would, so F1 peaks near where the two gauges cross. Which metric to optimize depends on the cost of a false alarm versus a miss — the theme of the decision threshold.

Trace it by hand

Ten scored predictions at threshold 0.5 (score at or above 0.5 predicts positive). The 5 actual positives scored 0.9, 0.8, 0.6, 0.4, 0.2; the 5 actual negatives scored 0.7, 0.55, 0.35, 0.25, 0.1. Counts verified with the site's threshold engine.

  1. Count the confusion cells

    TP=3,FP=2,FN=2,TN=3TP = 3, \quad FP = 2, \quad FN = 2, \quad TN = 3

    Positives at 0.9, 0.8, 0.6 clear the bar (TP); 0.4 and 0.2 are missed (FN). Negatives at 0.7 and 0.55 sneak over it (FP).

  2. Precision: when it says positive, is it right?

    P=TPTP+FP=33+2=0.6P = \frac{TP}{TP + FP} = \frac{3}{3 + 2} = 0.6

    Of the 5 points flagged positive, 3 really were.

  3. Recall: did it catch all the positives?

    R=TPTP+FN=33+2=0.6R = \frac{TP}{TP + FN} = \frac{3}{3 + 2} = 0.6

    Of the 5 actual positives, 3 were caught.

  4. Combine into F1

    F1=2PRP+R=2×0.6×0.60.6+0.6=0.721.2=0.6F_1 = \frac{2PR}{P + R} = \frac{2 \times 0.6 \times 0.6}{0.6 + 0.6} = \frac{0.72}{1.2} = 0.6

    When P and R are equal, their harmonic mean equals both. The imbalanced cases are where F1 bites.

What just happened: At threshold 0.5 this classifier is perfectly balanced: precision 0.6, recall 0.6, F1 0.6. The tension only appears when the threshold moves — the decision threshold page re-runs these exact ten predictions at 0.3 and 0.7 and watches P and R trade places.

Now Break It

Try this: Optimizing precision alone lets recall collapse — the model only predicts the easiest cases.

Control: Threshold slider (push to extreme)

What happens: One-sided! Chasing precision alone crashes recall — the model ignores most positives.

Where precision, recall & f1 is used

Precision and recall separate two distinct questions that accuracy blurs together. Precision asks, of everything the model flagged as positive, how many were actually positive, so it measures how much you can trust a positive prediction. Recall asks, of all the true positives that exist, how many did the model catch, so it measures coverage. In fraud detection a bank tuning for high recall wants to catch as many fraudulent transactions as possible even at the cost of reviewing some legitimate ones, while a spam filter often prioritizes precision so genuine email is rarely lost. The F1 score is the harmonic mean of the two, giving a single balanced number that punishes a model that sacrifices one to inflate the other.

A key misconception is treating precision and recall as independent goals you can maximize at once; usually they trade off. Lowering the decision threshold catches more positives and raises recall but tends to lower precision as more false alarms slip in, and raising the threshold does the reverse. Reporting only one is misleading: a model that flags everything as positive has perfect recall but terrible precision. Another pitfall is defaulting to F1 when the two errors have very different costs; F1 weights precision and recall equally, so if missing a positive is far worse than a false alarm, a weighted F-beta score or an explicit cost analysis reflects your priorities better.

Frequently asked questions

What is the difference between precision and recall?
Precision is the fraction of predicted positives that are actually positive, so it measures how trustworthy a positive prediction is. Recall is the fraction of actual positives the model successfully catches, so it measures coverage. High precision means few false alarms, while high recall means few missed positives.
What is the F1 score and when should I use it?
F1 is the harmonic mean of precision and recall, producing a single score that is high only when both are high. It is useful for imbalanced problems where accuracy is misleading and you want one balanced number. When one error type is far costlier, a weighted F-beta score is more appropriate.
Why does improving recall often hurt precision?
Recall and precision usually trade off as you move the decision threshold. Lowering the threshold labels more cases as positive, catching more true positives but also admitting more false positives, which raises recall and lowers precision. The right balance depends on the relative cost of misses versus false alarms.
When should I prioritize precision over recall, or vice versa?
Prioritize recall when missing a positive is costly, such as screening for a serious disease or catching fraud. Prioritize precision when false alarms are costly or annoying, such as a spam filter that must not hide real email. The application's consequences decide which matters more.
Why not just use accuracy instead of precision and recall?
Accuracy counts all correct predictions equally and can look excellent on imbalanced data even when the model never catches the rare class. Precision and recall focus on the positive class and reveal whether the model actually finds and correctly labels the cases you care about.

Written & reviewed by the ML Visualization team · Last updated .