F1 Score and Precision-Recall Calculator

Classification metrics

F1 score0.842
Precision0.800
Recall0.889
F2 / F0.5 scores0.870 / 0.816
How this was calculated
  1. Precision: 80 / (80 + 20) = 0.800.
  2. Recall: 80 / (80 + 10) = 0.889.
  3. F1 score: 2 x 0.800 x 0.889 / (0.800 + 0.889) = 0.842.
  4. Weighing recall higher gives F2 = 0.870; weighing precision higher gives F0.5 = 0.816.

A classifier makes two kinds of promise: when it speaks, is it right (precision), and of everything it should have caught, how much did it catch (recall)? The F1 score is the harmonic mean of the two promises - a single number that stays low unless both are kept. This page computes precision, recall and F1 from the three counts that define them - true positives, false positives, false negatives - plus the F2 and F0.5 variants that re-weight the trade.

The Matthews coefficient page on this site grades classifiers with all four confusion cells including true negatives; here the focus is the precision-recall axis that information retrieval, screening and detection systems are actually tuned along.

Worked examples

TP 80, FP 20, FN 10, F1 0.842

(80 · 20 · 10)

F1 score0.842
Precision0.800
Recall0.889
F2 / F0.5 scores0.870 / 0.816

Precision-leaning, F1 0.600

(45 · 5 · 55)

F1 score0.600
Precision0.900
Recall0.450
F2 / F0.5 scores0.500 / 0.750

Symmetric counts, F1 0.500

(30 · 30 · 30)

F1 score0.500
Precision0.500
Recall0.500
F2 / F0.5 scores0.500 / 0.500

Precision, recall and the harmonic mean

Precision = TP/(TP+FP) grades the positive calls; recall = TP/(TP+FN) grades the coverage of actual positives. Their harmonic mean, F1 = 2PR/(P+R), punishes imbalance between them: a precision of 1.0 with a recall of 0.1 earns an F1 of only about 0.18, where the arithmetic mean would have flattered with 0.55.

The first example - 80 true positives, 20 false alarms, 10 misses - gives precision 0.800, recall 0.889 and F1 0.842. Here recall is the stronger promise, and F1 sits between the two, closer to the weaker precision, exactly as the harmonic mean is designed to behave.

Equivalently, F1 = 2TP/(2TP + FP + FN): true negatives never appear. Whether that is a virtue depends on whether the negative class is background (retrieval: virtue) or substance (screening: see the MCC page).

  • Precision = TP / (TP + FP)
  • Recall = TP / (TP + FN)
  • F1 = harmonic mean = 2TP / (2TP + FP + FN)
  • True negatives do not enter F1

Worked examples: three classifiers

The recall-leaning classifier above: precision 0.800, recall 0.889, F1 0.842. Its 20 false alarms against 10 misses mark it as a system tuned to catch - the shape of a first-pass screen.

The precision-leaning classifier: 45 TP, 5 FP, 55 FN. Precision 0.900 but recall 0.450, so F1 falls to 0.600. It speaks rarely and is usually right - and misses over half of everything it exists to find. F1's demotion is the correct verdict for most detection purposes.

The symmetric classifier: 30 TP, 30 FP, 30 FN. Precision, recall and F1 all land at 0.500. When the two error counts balance the TP count, every member of the family agrees - a useful control case for checking any implementation.

The F2 / F0.5 pairs exactly as printed: 0.870 / 0.816 for the first example, 0.500 / 0.750 for the second, and 0.500 / 0.500 for the symmetric third.

F2 and F0.5: weighting the promises

The F-beta family re-weights the harmonic mean: F2 counts recall more heavily, F0.5 counts precision more heavily. The calculator prints both beside F1. In the first example F2 = 0.870 and F0.5 = 0.816 - the recall-weighted score rewards this classifier's stronger recall, the precision-weighted one taxes its 20 false alarms.

The second example reverses the lesson: with precision 0.900 and recall 0.450, F0.5 rises to 0.750 while F2 falls to 0.500. Same classifier, three scores - the beta is a declared value judgement about which error costs more, and reporting the family makes the judgement visible.

In the symmetric third example all three coincide at 0.500, as they must: re-weighting changes nothing when the two promises are kept equally.

Trading precision against recall

Most classifiers expose a threshold, and moving it walks the precision-recall curve: lower it and recall rises while precision falls. F1 picks the point where the harmonic balance is best, which is a reasonable default and a specific value judgement - it weighs a false alarm and a miss in the ratio the counts imply, no more, no less.

Asymmetric costs are what F2 and F0.5 are for. A cancer screen buys recall at almost any precision price (F2 thinking); a spam filter that eats real mail buys precision (F0.5 thinking). The metrics describe the trade; the domain picks the point.

What no scalar can do is choose the costs for you. The three examples are the same technology at three operating points; the right one is a decision about consequences.

Threshold honesty: quote the threshold beside the F1. An F1 without its operating point is a best-case advertisement, not a measurement.

F1 in retrieval and screening practice

Information retrieval grew up on this pair: a search that returns everything has perfect recall and useless precision; one that returns a single perfect document has the reverse. F1 summarises a results page the way a user experiences it - both failures hurt - which is why it survives as a headline metric decades after van Rijsbergen proposed the family.

Screening programmes live at the high-recall corner: the first example's shape (recall 0.889 against precision 0.800) is a mild version of the deliberate purchase of sensitivity with false alarms, rational when a cheap second stage can clear the false positives and a missed case is expensive.

Fraud and intrusion detection live at the opposite discipline: alert volume is capped by analyst hours, so precision at a fixed recall floor is the operating constraint. Same formulas, opposite corners.

Reporting classifier performance honestly

The minimum honest report is the counts at a stated threshold on a stated test set. Precision, recall, F1, F2 and F0.5 all follow from TP, FP and FN - as this page demonstrates - and any reader can recompute the metric their own costs prefer, including MCC once TN is supplied.

Beware test-set threshold tuning: choosing the threshold that maximises F1 on the test set and then reporting that F1 grades the tuning as much as the classifier. Tune on validation data; report on untouched data.

Class prevalence belongs in the report as well: precision is prevalence-dependent (the same classifier earns different precision at different base rates), while recall is a property of the classifier alone. A precision quoted without a prevalence is a number waiting to be misunderstood.

Worked check: F1 from the counts directly

The count form gives a one-line audit of the first example: 2TP = 160, FP + FN = 30, so F1 = 160/190 = 0.842 - matching the harmonic-mean route through precision 0.800 and recall 0.889. Two algebraically different paths landing on the same number is the cheapest correctness test a metrics implementation can run.

The second example audits the same way: 2 x 45 = 90 over 90 + 5 + 55 = 150, giving 0.600. Note how the 55 misses dominate the denominator - the arithmetic form of the recall problem.

When a library's F1 disagrees with the count form, the usual cause is a different averaging mode silently applied in multi-class settings. The counts are the ground truth; insist on seeing them.

Precision and recall beyond classification

The pair predates machine learning: van Rijsbergen built the F-measure for document retrieval in the 1970s, where a results list has no true negatives worth counting and the harmonic mean captured a searcher's twin frustrations - junk returned, treasure missed. That origin explains F1's indifference to true negatives better than any modern rationalisation.

Object detection inherited the framework with a spatial twist (a detection counts as TP only if it overlaps the truth enough), and recommender systems use precision-at-k and recall-at-k, the list-truncated descendants. The arithmetic on this page is the trunk of that family tree.

Knowing the lineage helps choose: tasks shaped like retrieval inherit F1 naturally; tasks shaped like diagnosis, where the negative class is real people correctly cleared, should at least glance at MCC before settling.

Averaging traps in multi-class reports

This page computes the binary family from raw counts, but the numbers are routinely averaged across classes in multi-class work, and the averaging mode changes the answer. Micro-averaging pools the counts first and, in single-label problems, collapses to accuracy; macro-averaging grades each class separately and exposes weak small classes. A reported 'F1 of 0.84' without its averaging mode is half a result.

The discipline transfers from the binary examples: the first example's 0.842 is a statement about one class's TP, FP and FN (80, 20, 10). A multi-class report owes the reader the same counts per class, from which every averaging mode can be recomputed.

When classes matter individually - rare diagnoses, minority intents - per-class F1 with the counts attached is the truthful format, and this page's three worked examples are the template for each row.

A closing note on defaults: when a paper reports a single F-score without naming the beta, it means F1 - the balanced member - and the examples here show what that balance implies: the first classifier's 0.842 rewards its even-handedness, the second's 0.600 exposes its lopsidedness. If your costs are not balanced, say which beta you used and why; the family exists so the choice can be explicit rather than inherited.

FAQs

What is the F1 for TP 80, FP 20, FN 10?

0.842, from precision 0.800 and recall 0.889.

What is the precision there?

0.800.

What is the recall when TP is 45 and FN is 55?

0.450, dragging F1 to 0.600 despite 0.900 precision.

What if all the counts are 30?

F1 0.500 - precision, recall and F1 all coincide.

What is the F2 of the first example?

0.870 - the recall-weighted variant rewards its stronger recall.

And its F0.5?

0.816 - precision counts more, taxing the 20 false alarms.

Sources

Related calculators

Cramer's V Calculator
Cramer's V effect size for a contingency table from the chi-square statistic, the sample size and the table dimensions, with Cohen's degrees-of-freedom-adjusted benchmarks for the strength of association.
Chi-Square Test Calculator (2x2)
The chi-square test of independence for a 2x2 contingency table: statistic, p-value at 1 degree of freedom, and the phi effect size.
Odds Ratio Calculator
Odds ratio and relative risk from a 2x2 table (exposed/unexposed × outcome/no outcome), with the 95% confidence interval for the odds ratio by the log method.