Skip to main content
v2026.11,858 entries · CC-BY 4.0

Precision and Recall Formula: Definitions, Worked Example and How to Report It

Precision = TP/(TP+FP); recall = TP/(TP+FN). See the symbols, a worked example at two thresholds, how to interpret and report them, and code to compute both.

Written and maintained by CASRAI Editorial Board

Last updated

Precision is the share of a model’s positive calls that are correct, and recall is the share of all real positives that the model finds. The two formulas are precision = TP / (TP + FP) and recall = TP / (TP + FN). This guide defines each symbol, works one confusion matrix at two decision thresholds so you can see the trade-off in real arithmetic, and shows how to report and compute both.

What is precision and recall?

Both measures score a classifier that sorts items into positive and negative: documents as relevant or not, patients as diseased or not, emails as spam or not. Google’s Machine Learning Crash Course defines recall as “the proportion of all actual positives that were classified correctly as positives” and precision as “the proportion of all the model’s positive classifications that are actually positive”. Precision asks “when the model says positive, how often is it right?” Recall asks “of everything that really is positive, how much did the model catch?”

Recall is also called sensitivity, and the scikit-learn documentation notes this directly. In diagnostic-test language, recall is the true positive rate and precision is the positive predictive value (see positive predictive value). The companion pair is covered in sensitivity vs specificity.

Precision and recall formula

Every symbol comes from the four cells of a confusion matrix. The scikit-learn User Guide describes them as: tp, a correct result; fp, an unexpected result; fn, a missing result; and tn, a correct absence of result.

Symbol Name Meaning
TP True positives Actual positives the model called positive
FP False positives Actual negatives the model called positive
FN False negatives Actual positives the model called negative
TN True negatives Actual negatives the model called negative

Precision = TP / (TP + FP). The denominator is everything the model flagged as positive.

Recall = TP / (TP + FN). The denominator is everything that is actually positive. Note that TN appears in neither formula, which is why both measures ignore how well the model handles easy negatives.

When you need a single number that combines the two, see the F1 score formula.

Precision and recall examples

Worked example at two thresholds

Suppose a screening model scores 100 items, of which 20 are truly positive and 80 are truly negative. The model gives each item a score, and an item is flagged positive when its score meets the threshold.

Threshold A (strict). The model flags 16 items. Of these, 12 are truly positive and 4 are not.

  • TP = 12, FP = 4
  • FN = 20 − 12 = 8 (positives that were not flagged)
  • TN = 80 − 4 = 76
  • Check: 12 + 4 + 8 + 76 = 100
  • Precision = 12 / (12 + 4) = 12 / 16 = 0.750
  • Recall = 12 / (12 + 8) = 12 / 20 = 0.600

Threshold B (lenient). Lowering the threshold, the model flags 30 items. Of these, 17 are truly positive and 13 are not.

  • TP = 17, FP = 13
  • FN = 20 − 17 = 3
  • TN = 80 − 13 = 67
  • Check: 17 + 13 + 3 + 67 = 100
  • Precision = 17 / (17 + 13) = 17 / 30 = 0.567
  • Recall = 17 / (17 + 3) = 17 / 20 = 0.850
Threshold Flagged TP FP FN Precision Recall
A (strict) 16 12 4 8 0.750 0.600
B (lenient) 30 17 13 3 0.567 0.850

Moving from A to B raised recall from 0.600 to 0.850 and lowered precision from 0.750 to 0.567. This is the pattern Google’s Crash Course describes: raising the classification threshold tends to reduce false positives, and “precision and recall often show an inverse relationship, where improving one of them worsens the other.” The counts here are an illustrative calculation, not data from a real study.

How to interpret precision and recall

Read the two numbers together, and in light of what a wrong call costs.

Pattern What it says
High precision, low recall Positive calls are mostly right, but many real positives are missed (false negatives dominate)
Low precision, high recall Most real positives are found, but many flagged items are wrong (false positives dominate)
Both high The model flags few wrong items and misses few real ones
Both low The model is both noisy and incomplete

Prefer recall when a missed positive is the costly error, and precision when a false alarm is. Accuracy can mislead when positives are rare: Google’s Crash Course states that with few actual positives recall is a more meaningful metric than accuracy. In the example above, Threshold A has accuracy (12 + 76) / 100 = 0.88 while still missing 8 of 20 positives. For a threshold-free view, see the ROC curve and AUC.

Assumptions and common mistakes

  • Precision depends on how common positives are. Precision is a positive predictive value, so the same model gives a different precision when the share of true positives in the data changes. Compare precision only across datasets with similar class balance. See prevalence vs incidence for the underlying idea.
  • A very rare positive class makes precision unstable. Google’s Crash Course notes that with very few positives, precision is less meaningful and less useful as a metric.
  • Undefined cases. Precision is undefined when TP + FP = 0 (nothing was flagged) and recall is undefined when TP + FN = 0 (no actual positives). Conventions vary; scikit-learn offers a zero_division parameter to set the value returned in such cases. State the convention you used.
  • Reporting one without the other. A model can reach perfect precision by flagging a single sure item, or perfect recall by flagging everything.
  • Not stating the threshold. Both values change with the cut-off, as the worked example shows.
  • Confusing precision with measurement precision. Here precision means positive predictive value, not the repeatability of a measurement.

How to report precision and recall

Report the counts or the sample size, the decision threshold, and both measures. An example sentence:

At a decision threshold of 0.50, the classifier achieved a precision of 0.75 and a recall of 0.60 (TP = 12, FP = 4, FN = 8, TN = 76; N = 100). Where a measure was undefined, it was set to 0.

Give the same number of decimals throughout and name the software and version used to compute the values. For a single combined figure, see the F1 score formula.

How to calculate precision and recall in Excel, R or Python

Excel

Put TP in B1, FP in B2 and FN in B3, then:

Precision: =B1/(B1+B2)
Recall:    =B1/(B1+B3)

R

tp <- 12; fp <- 4; fn <- 8
precision <- tp / (tp + fp)   # 0.75
recall    <- tp / (tp + fn)   # 0.60

Python (scikit-learn)

from sklearn.metrics import precision_score, recall_score

y_true = [0, 1, 0, 1]
y_pred = [0, 1, 0, 0]
precision_score(y_true, y_pred)  # 1.0  (tp=1, fp=0)
recall_score(y_true, y_pred)     # 0.5  (tp=1, fn=1)

This is the example used in the scikit-learn documentation. Pass zero_division to control the value returned when a denominator is zero.

Frequently asked questions

What is precision and recall?

Precision is the proportion of a model’s positive predictions that are correct, TP / (TP + FP). Recall is the proportion of all actual positives the model finds, TP / (TP + FN). Together they describe the two kinds of error a classifier makes: false alarms and misses.

Is recall the same as sensitivity?

Yes. scikit-learn notes that recall is sometimes called sensitivity, and both equal the true positive rate.

Why does improving precision usually lower recall?

A stricter threshold flags fewer items, which removes false positives but also drops some true positives. The worked example above shows precision falling from 0.750 to 0.567 as recall rises from 0.600 to 0.850.

When should I use precision and recall instead of accuracy?

Use them when positives are rare or when the two error types have different costs. Accuracy counts true negatives, which can dominate the result and hide missed positives.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Precision and Recall Formula: Definitions, Worked Example and How to Report It

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.