Precision, Recall and Why Accuracy Can Lie to You

Why a 99% accurate model can be useless, what precision and recall actually measure, and how to choose the right metric for your problem.

Share on Linkedin Share on WhatsApp

Estimated reading time: 7 minutes

Article image Precision, Recall and Why Accuracy Can Lie to You

Imagine you build a model to detect a rare disease that affects one person in every thousand. You test it and it reports 99.9% accuracy. Impressive — until you look closer and realize the model simply predicts “healthy” for everyone. It never catches a single sick patient, and yet the number on the report looks spectacular.

This is the single most common trap in machine learning evaluation, and it is why precision and recall exist.

Start with the confusion matrix

Every classification metric is built from four counts. For a model that answers yes or no, each prediction falls into one of these boxes:

Actually positiveActually negative
Predicted positiveTrue Positive (TP)False Positive (FP)
Predicted negativeFalse Negative (FN)True Negative (TN)

A helpful way to remember the two error types: a false positive is a false alarm, and a false negative is a miss. Almost every real-world decision about a model comes down to deciding which of those two hurts more.

The three metrics, in plain words

  • Accuracy = (TP + TN) / everything. Of all predictions, how many were right?
  • Precision = TP / (TP + FP). When the model says yes, how often is it correct?
  • Recall = TP / (TP + FN). Of everything that was actually positive, how much did the model find?

Notice what precision and recall have in common: neither one uses true negatives. That is exactly why they survive the rare-disease trap. In our example, the model that predicts “healthy” for everyone has zero true positives, so both precision and recall collapse to zero — which is an honest description of a useless model.

A worked example

Say a spam filter processes 1,000 emails. 100 are genuinely spam. The filter flags 80 messages, and 60 of those really were spam.

  • TP = 60 (correctly flagged spam)
  • FP = 20 (legitimate emails wrongly flagged)
  • FN = 40 (spam that slipped through)
  • TN = 880 (legitimate emails correctly left alone)

Precision = 60 / 80 = 75%. Recall = 60 / 100 = 60%. Accuracy = 940 / 1000 = 94%.

The 94% sounds great and tells you almost nothing. The two numbers that matter are that one in four flagged messages was innocent, and that four out of ten spam messages still reached the inbox.

The trade-off is real and unavoidable

Most classifiers do not output a hard yes or no. They output a probability, and you choose a threshold — say, flag anything above 0.5.

Move that threshold up and the model becomes conservative: it only says yes when very confident. Precision rises, recall falls. Move it down and the model becomes eager: it catches more real positives but also more false alarms. Recall rises, precision falls.

You cannot maximize both by tuning the threshold alone. Improving both at once requires a genuinely better model — better features, better data, better architecture.

Which one should you optimize?

The answer comes from the cost of each mistake, not from statistics.

SituationCostlier errorPrioritize
Screening for a serious illnessMissing a sick patientRecall
Spam filteringDeleting an important emailPrecision
Fraud detection on transactionsLetting fraud throughRecall
Automatically banning user accountsPunishing an innocent userPrecision
Search results on page oneShowing irrelevant resultsPrecision
Legal document discoveryMissing a relevant documentRecall

Notice the pattern: when a human reviews the flagged cases afterwards, you can afford lower precision, because a person filters the false alarms. When the model acts automatically with no review, precision matters enormously.

The F1 score, and when it misleads

Sometimes you want one number. The F1 score is the harmonic mean of precision and recall:

F1 = 2 × (precision × recall) / (precision + recall)

The harmonic mean is used instead of a simple average for a good reason: it punishes imbalance. A model with 100% precision and 2% recall has an arithmetic average of 51% but an F1 of about 4% — a much more honest summary.

The catch is that F1 assumes precision and recall matter equally. In the disease-screening example they clearly do not. When one side matters more, the F-beta score lets you weight recall higher (beta greater than 1) or precision higher (beta less than 1).

Curves tell you more than points

Because everything depends on the threshold, a single metric is a snapshot. Two curves show the whole picture:

  • The precision–recall curve plots the two against each other across every possible threshold. It is the better choice when positives are rare.
  • The ROC curve plots the true positive rate against the false positive rate, summarized by the area under the curve (AUC). It is intuitive and widely used, but it can look flattering on heavily imbalanced data, because the huge pool of true negatives keeps the false positive rate small.

What to do in practice

  1. Look at your class balance first. If positives are under roughly 10% of the data, treat accuracy as decoration, not evidence.
  2. Write down the cost of each error type before training — ideally in money, time, or risk, not in abstract points.
  3. Always inspect the confusion matrix, not just the summary metrics. The raw counts often reveal a pattern the ratios hide.
  4. Tune the threshold as a deliberate decision, not by leaving it at the default 0.5.
  5. Evaluate on data that looks like production. If positives are rare in the real world, do not rebalance the test set — rebalance training if needed, but let the test set stay honest.

Conclusion

Accuracy is a comfortable number. Precision and recall are useful ones. They force you to answer a question that no algorithm can answer for you: which mistake are you willing to make more often? Once that question is settled, the metric to optimize becomes obvious, and so does the threshold.

If you want to go deeper into model evaluation, data preparation and the fundamentals behind these techniques, the free Artificial Intelligence and Machine Learning courses on Cursa are a solid place to continue.

NTFS, exFAT, FAT32 and APFS: Choosing the Right File System for a Drive

Understand what a file system does and how NTFS, exFAT, FAT32, APFS and ext4 differ, so you can format drives without losing compatibility.

Text Encoding Explained: ASCII, Unicode and Why You Sometimes See Strange Symbols

Learn how computers store text, what ASCII and Unicode actually are, why UTF-8 became the standard, and how to fix files that display garbled characters.

Idempotency in APIs: Why Retrying a Request Should Be Safe

Learn what idempotency means in backend development, which HTTP methods provide it, and how idempotency keys prevent duplicate operations.

What Is a CDN? How Content Delivery Networks Make Websites Fast

Learn what a CDN is, how edge caching and cache headers work, what a cache hit means, and when a CDN helps — or does not.

Semantic Versioning Explained: What a Number Like 2.4.1 Actually Tells You

MAJOR.MINOR.PATCH is a promise, not decoration. Learn to read version numbers and understand dependency range symbols.

What Is a Virtual Machine? Virtualization Explained for Beginners

Learn what a virtual machine is, how hypervisors work, how VMs differ from containers, and when to use each one.

How HTTPS Works: Certificates, the TLS Handshake and What the Padlock Really Means

A beginner-friendly walkthrough of HTTPS: what TLS certificates prove, how the handshake works, and what the browser padlock does not guarantee.

Big O Notation Explained: How to Talk About Code Efficiency

A beginner-friendly guide to Big O notation: what it measures, the most common complexity classes, and how to reason about the cost of your code.