Velamuvi AIAcademy
Probability

Lesson 7 of 16 · Conditioning

The Base Rate Trap

The base rate trap: why a positive result from a 99% accurate test can mean only a 1 in 6 chance of disease. Natural frequencies, Bayes and ML precision.

  • 7 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Explain the base rate trap (base rate neglect)
  • Define sensitivity, specificity and false positive rate
  • Solve Bayes problems with natural frequencies
  • See how the base rate changes what a positive result means
  • Connect the base rate trap to precision in machine learning

A puzzle

A disease affects 1% of people. A test for it is very good:

  • If you have the disease, it's positive 99% of the time.
  • If you don't, it's wrongly positive only 5% of the time.

You test positive. How likely is it that you have the disease?

Most people, including many doctors in published studies, answer something like 95%. The real answer is about 17%. The gap between those numbers is the base rate trap.

Test vocabulary

TermMeaningHere
SensitivityP(positive | disease): how many real cases the test catches99%
SpecificityP(negative | no disease): how many healthy people it clears95%
False positive rateP(positive | no disease) = 1 − specificity5%

None of these is the number the patient wants, P(disease | positive).

Natural frequencies: the easy way

Bayes' theorem gives the answer, but there's an easier way to see it: instead of probabilities, imagine a crowd of real people. These counts are called natural frequencies.

Try it yourselfPython
people = 10_000
p_disease = 0.01             # 1% of people have the disease (the base rate)
sensitivity = 0.99           # P(positive | disease)
false_positive_rate = 0.05   # P(positive | no disease)

sick = people * p_disease
healthy = people - sick
true_positives = sick * sensitivity
false_positives = healthy * false_positive_rate

print(f"{sick:.0f} sick people     -> {true_positives:.0f} test positive")
print(f"{healthy:.0f} healthy people -> {false_positives:.0f} test positive")
print(f"P(disease | positive) = {true_positives:.0f} / {true_positives + false_positives:.0f}"
      f" = {true_positives / (true_positives + false_positives):.3f}")

Picture the 10,000 people:

  • 100 are sick. The test catches 99 of them.
  • 9,900 are healthy. 5% of them, 495 people, test positive anyway.

So there are 594 positive results, and only 99 of them come from sick people: 99 ÷ 594 ≈ 0.167, about 1 in 6. The false positives win because they come from the huge healthy group. A small error rate applied to a lot of people is a lot of errors.

The base rate changes everything

The same test means very different things in different groups. Here it is with four base rates, and with a second test:

Try it yourselfPython
def bayes(prior, p_e_given_h, p_e_given_not_h):
    p_e = p_e_given_h * prior + p_e_given_not_h * (1 - prior)
    return p_e_given_h * prior / p_e

# The same test (99% sensitivity, 5% false positives) in different groups of people
for base_rate in (0.001, 0.01, 0.1, 0.5):
    print(f"base rate {base_rate:>5}: P(disease | positive) = {bayes(base_rate, 0.99, 0.05):.3f}")

# A second, independent positive test: the first posterior becomes the new prior
after_one = bayes(0.01, 0.99, 0.05)
after_two = bayes(after_one, 0.99, 0.05)
print(f"one positive: {after_one:.3f}   two positives: {after_two:.3f}")
  • For a rare condition (1 in 1,000), a positive result means only a 2% chance of disease.
  • In a group where half the people are sick, the very same result means 95%.
  • A second independent positive test raises 17% to about 80%: the first posterior becomes the new prior. That's why doctors confirm a surprising result with another test.

The same trap in machine learning

In machine learning, P(disease | positive) has another name: precision, the share of positive predictions that are correct. Sensitivity is called recall.

Rare events such as fraud, defects or diseases are where this matters most. A fraud model can catch 95% of fraud with only a 1% false alarm rate and still produce mostly false alarms, which you'll calculate in the exercise below.

Common mistakes

Practice exercise

A fraud detector catches 95% of fraud and has only a 1% false alarm rate. Out of 100,000 payments, how many alerts are real, and what share of alerts are fraud?

Your solutionPython
transactions = 100_000
p_fraud = 0.002              # 0.2% of card payments are fraud
p_alert_given_fraud = 0.95   # the system flags 95% of fraud
p_alert_given_legit = 0.01   # and wrongly flags 1% of honest payments

# Use natural frequencies. Print three things on one line:
#   the number of alerts that really are fraud (a whole number),
#   the number of false alarms (a whole number),
#   and P(fraud | alert), rounded to 2 decimals.
Knowledge check

The same test, with the same sensitivity and false positive rate, is used in two places. In which place does a positive result mean the highest chance of disease?

Summary

  • The base rate is how common something is before any evidence; it's the prior.
  • Base rate neglect means judging by the test's accuracy alone, and it can be badly wrong.
  • Natural frequencies (“imagine 10,000 people”) make Bayes problems easy to see.
  • When the condition is rare, even a good test produces mostly false positives.
  • In machine learning, P(real | flagged) is precision, and it depends on the base rate.

Next: Naive Bayes intuition.

Finished reading? Tick it off to track your progress.