Precision Recall and F1 Score

Authors 6 articles 58 min total read
Definition
Three classification metrics that quantify different aspects of prediction accuracy. Precision measures correctness among predicted positives, recall measures coverage of actual positives, and F1 score balances both through a harmonic mean for single-number model comparison.
Also called: precision and recall, F1 measure, F-score

What precision and recall are

Every time a model makes a yes-or-no prediction — spam or not spam, fraud or legitimate, tumor or healthy tissue — some of those predictions will be wrong. The question is which type of wrong matters more for your situation. Precision, recall, and F1 score exist to answer exactly that. They give you three different lenses for evaluating a classifier’s performance, each one highlighting a different kind of mistake. Without them, you cannot see the errors that cost money, time, or trust.

Think of it like a search engine returning results for your query. Precision asks: “Of all the results the engine returned, how many were actually relevant?” Recall asks: “Of all the relevant pages that exist, how many did the engine find?” A search engine that returns only one result — but a perfect one — has high precision and low recall. One that returns every page on the internet has perfect recall but terrible precision. Neither extreme is useful on its own.

These two metrics are calculated from four counts in a confusion matrix — a 2x2 grid that tallies true positives (correctly predicted yes), false positives (predicted yes but actually no), true negatives (correctly predicted no), and false negatives (predicted no but actually yes). Precision equals true positives divided by the sum of true positives and false positives. Recall equals true positives divided by the sum of true positives and false negatives.

F1 score resolves the tension between precision and recall. It is the harmonic mean of the two, which means it penalizes extreme imbalances rather than averaging them away. A model with 95% precision but 10% recall would get a seemingly acceptable arithmetic average of 52.5%, but its F1 score drops to just 18.2% — exposing the imbalance that a simple average hides. This property makes F1 particularly useful when you need a single number to compare classifiers, especially on datasets where one class heavily outnumbers the other.

The confusion matrix ties all three metrics together. Reading the matrix row by row and column by column shows you exactly where predictions go right and where they break down — and precision, recall, and F1 are simply different ways of summarizing that breakdown into numbers you can compare across models.

Raising the threshold buys precision with missed positives; decide which error costs more before you tune. · More AI cheat sheets
  • Precision, recall, and F1 all derive from the confusion matrix’s four cells, but each punishes a different kind of error — picking the right one is a modeling decision, not an implementation detail.
  • On imbalanced data, F1 can look strong on a nearly useless classifier because it ignores true negatives entirely; MCC and PR-AUC read the full matrix instead.
  • Averaging strategy — macro, micro, or weighted — changes what the same F1 number is telling you, so a score reported without its averaging method is incomplete.
  • In production, medical AI, content moderation, and fraud detection each choose different metrics for the same math, because a false positive and a false negative rarely cost the same.

How precision and recall are used in practice

The most common place you encounter these metrics is in model evaluation reports. When a data science team presents a classifier — whether it detects spam emails, flags fraudulent transactions, or categorizes support tickets — the performance summary almost always includes precision, recall, and F1 alongside accuracy. Libraries like scikit-learn generate full classification reports with a single function call, displaying these metrics broken down per class.

The reason teams rely on these metrics instead of plain accuracy is class imbalance. If only 2% of transactions are fraudulent, a model that labels everything “legitimate” achieves 98% accuracy while catching zero fraud. Precision, recall, and F1 expose this failure because they focus specifically on how well the model handles the minority class — the one that usually matters most.

In practice, which metric you prioritize depends on the cost of errors. Medical screening favors recall — missing a disease (false negative) is far worse than ordering an extra test (false positive). Email spam filtering favors precision — blocking a legitimate email is more disruptive than letting one spam message through.

When comparing models, check the F1 score first to spot imbalance, then look at precision and recall individually to understand which error type each model trades off. Two models with identical F1 but different precision-recall splits may perform very differently in your specific use case.

The precision-recall-F1 reading path: matrix first, stakes last

Start with how the confusion matrix drives classification evaluation — it introduces the four-cell table these three metrics are built from, the same table that anchors the confusion matrix itself, so you get both readings in one sitting. Then read the building blocks behind precision, recall, and F1, which extends the binary case into multi-class problems and settles the vocabulary — true positive, macro average, weighted average — every later article assumes you already have.

Once that vocabulary is fixed, why F1 score fails on imbalanced datasets is the read that stops you trusting a high score on skewed data, and the scikit-learn and TorchMetrics guide turns that caution into a working threshold-tuning workflow you can run before a model ships.

For the stakes once a model is live, F1 score in production tracks how medical, moderation, and fraud teams each weight the metric differently, and optimizing for the wrong number closes the path with the case for checking F1 by subgroup, not only in aggregate, before a high-stakes classifier ships.

MAX asks: 'My model held a 0.91 F1 in testing — why did it collapse the moment we deployed on live traffic?' MONA answers: 'F1 is only as trustworthy as the class balance you measured it on — shift the ratio of positives and the same formula tells a different story.' — comic dialog.
The formula didn't change between testing and production. The data underneath it did.

How precision, recall, and F1 differ from other evaluation layers

Two neighbours get folded into “classification metrics” when they measure something else entirely.

Precision, recall, and F1 score a classifier against ground-truth labels it was built to predict. The MMLU benchmark scores a model’s answers against a fixed multiple-choice answer key — the same idea of comparing output to a correct answer, but MMLU grades general knowledge, not a deployed classifier’s error trade-off.

Precision, recall, and F1 also require a bounded label space and a labeled test set. LLM-as-a-judge exists for the opposite case — open-ended text with no fixed label space — by having another model grade the output instead of counting matches against a key. Reach for LLM-as-a-judge only once a task stops being a classification problem with a countable confusion matrix.

When precision and recall fit — and when they don't

ScenarioUseAvoid
Binary classification with imbalanced classes (fraud detection, disease screening)✅
You need a single metric to compare multiple classifiers quickly✅
The cost of false positives and false negatives differs significantly for your use case✅
Regression tasks where you predict continuous values like price or temperature❌
Multi-label tasks where partial matches matter (Jaccard or Hamming distance fits better)❌
Both classes are equally distributed and accuracy already tells the full story❌

Common questions about precision, recall, and F1

Q: Is a single F1 score enough to sign off on a classifier before it reaches production? A: No — F1 alone hides both the class-imbalance problem and any subgroup disparity. On skewed data a near-useless classifier can still post a high F1, which is why MCC and PR-AUC read the confusion matrix more completely before you trust the number enough to ship.

Q: Why does the same F1 score mean something different in a fraud model than in a medical one? A: Because F1 assumes precision and recall matter equally, and production teams rarely agree that they do — a missed fraud case and a missed diagnosis carry different costs. How medical AI, moderation, and fraud detection choose their metrics maps which industries weight which error.

Q: Can two classifiers with identical F1 scores still treat groups of people differently? A: Yes — an aggregate F1 score is computed across the whole dataset, so it can average away an error rate that is far worse for one subgroup than another. Optimizing for the wrong number traces exactly how that averaging hides disparate impact.

Q: Which averaging method should I report — macro, micro, or weighted F1? A: State whichever you use, because each tells a different story about the same model: macro treats every class equally, weighted respects class frequency, and reporting a bare “F1 score” without naming one is not reproducible. The scikit-learn and TorchMetrics guide covers the code-level trade-off.

Q: Do precision and recall only apply to binary yes/no classifiers? A: No — both extend to multi-class problems once you decide how to combine per-class scores, which is exactly where macro versus micro averaging comes in. From true positives to macro averaging builds that extension from the binary case.

Part of the model evaluation theme · closest neighbour: the confusion matrix. Coming to metrics from a software-testing background? Start with the story: Model Evaluation for Developers: What Maps and What Misleads.

1

Understand the Fundamentals

Precision, recall, and F1 score quantify different facets of classification accuracy. These articles explain why a single metric never tells the full story and how the confusion matrix connects them.

2

Build with Precision Recall and F1 Score

The practical guides cover choosing between precision and recall for your use case, calculating F1 variants in code, and tuning classification thresholds to match real-world trade-offs.

4

Risks and Considerations

Optimizing for F1 score without examining subgroup performance can hide bias and cause real harm. These articles explore what goes wrong when a single aggregate number drives high-stakes decisions.