Home / Probability

Bayes' Theorem

A test is 99% accurate and you test positive. Are you 99% likely to be ill? Almost certainly not — and this grid of 10,000 people shows exactly why.

Controls

base rate P(D)1.0%
sensitivity P(+|D)99%
specificity P(−|not D)99%

has it & tests positive
healthy but tests positive
has it, missed by test
healthy, correctly negative

10,000 People, One Square Each

natural frequencies

Live Calculation

true positives
0
false positives
0
all positives
0
P(ill | positive)
0%

Bayes' Theorem

How to update a belief when evidence arrives — and why "99% accurate" is not what you think.

Quick Context

Bayes' theorem takes a prior belief and revises it in light of new evidence. It is the mathematics of changing your mind correctly.

P(D | +) = P(+ | D) × P(D) / P(+)

The Direction Everyone Confuses

The whole difficulty is that P(+ | D) and P(D | +) are different questions:

  • P(+ | D)given that you are ill, how likely is a positive test? This is the test's sensitivity, the number printed on the box.
  • P(D | +)given a positive test, how likely is it that you are ill? This is what you actually want to know.

They can differ enormously. Swapping them is called the base rate fallacy, and studies repeatedly find that most doctors get this exact question wrong.

Count People, Not Percentages

The grid shows 10,000 people, one square each. With a 1% base rate and a 99% accurate test:

  • 100 people actually have it. The test catches 99 of them.
  • 9,900 are healthy. The test wrongly flags 1% of them — 99 people.
  • So 198 positives in total, of which only 99 are real. P(ill | positive) = 50%.

A coin flip — from a test that is genuinely 99% accurate. The reason is simply that there are so many more healthy people that even a tiny error rate applied to them produces as many false alarms as there are true cases. Presenting the problem as counts instead of percentages makes this obvious, which is why this format is called natural frequencies.

The Base Rate Dominates

Drag the base rate slider from 0.1% upward and watch the answer climb. The test never changed — only how common the condition is. This is why:

  • Mass screening for rare diseases produces mostly false positives, and follow-up testing is essential.
  • A positive result means far more when you already had symptoms — symptoms raise your prior before the test is even run.
  • Specificity matters more than sensitivity for rare conditions: false positives are drawn from the huge healthy majority. Try dropping specificity by just 1% and watch the answer collapse.

Where It Appears in ML

Bayes underpins the Naive Bayes classifier, which asks P(class | features) by flipping it into P(features | class) × P(class). The same asymmetry explains why a fraud detector with excellent accuracy still drowns analysts in false alarms — fraud is rare, so the base rate works against you. It is also why accuracy is a poor metric on imbalanced data, and why precision and recall exist.

Interactive Exploration Guide

  1. Start at the default (1% base rate, 99/99 test) and read the answer: about 50%, not 99%.
  2. Drop the base rate to 0.1%. The posterior falls to roughly 9% — a positive result now means you are still probably fine.
  3. Raise the base rate to 40%. Now a positive is highly meaningful. Same test, completely different conclusion.
  4. Return to 1% and drop specificity to 95%. False positives swamp the true ones and confidence collapses — a small change in specificity matters far more than sensitivity here.
  5. Count the amber squares against the red ones in the grid. That visual ratio is the answer.

Key Takeaway

Evidence updates a prior; it does not replace it. When a condition is rare, even an excellent test produces mostly false positives, because the healthy majority is so much larger. Always ask how common the thing was before the evidence arrived.

Cheat sheet

Bayes' Theorem

A test is 99% accurate and you test positive. Are you 99% likely to be ill? Almost certainly not — and this grid of 10,000 people shows exactly why.

MATHS · vizlearn.in/maths/bayes_theorem.html