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.
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.
How to update a belief when evidence arrives — and why "99% accurate" is not what you think.
Bayes' theorem takes a prior belief and revises it in light of new evidence. It is the mathematics of changing your mind correctly.
The whole difficulty is that P(+ | D) and P(D | +) are different questions:
They can differ enormously. Swapping them is called the base rate fallacy, and studies repeatedly find that most doctors get this exact question wrong.
The grid shows 10,000 people, one square each. With a 1% base rate and a 99% accurate test:
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.
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:
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.
Bayes' theorem is the rule for revising what you believe when new information arrives.
P(A|B) = P(B|A) × P(A) / P(B)
Each piece has a name and a job:
In words: new belief = old belief × how well the evidence fits, normalised.
A disease affects 1 in 1,000 people. A test is 99% accurate in both directions: it catches 99% of cases and produces a false positive 1% of the time.
You test positive. What is the probability you have the disease?
Most people say 99%. Work it through on 100,000 people:
| Has disease | No disease | Total | |
|---|---|---|---|
| Test positive | 99 | 999 | 1,098 |
| Test negative | 1 | 98,901 | 98,902 |
| Total | 100 | 99,900 | 100,000 |
Of the 1,098 positive results, only 99 are real. So the probability is 99 / 1,098 = 9%.
The test is genuinely 99% accurate. The answer is still 9%, because the disease is rare and the 99,900 healthy people generate ten times as many false positives as there are true cases.
This is base rate neglect, and it is the single most consequential probability error in medicine, security screening, fraud detection and machine learning evaluation. Whenever the positive class is rare, the prior dominates.
The article's 50% is arithmetic, not rhetoric. Change base_rate and run it again — the test's accuracy never moves.
The same calculation across six base rates. Nothing about the test changes; the answer moves from 9% to 99%.
There is a version of the theorem that is easier to compute in your head:
posterior odds = prior odds × likelihood ratio
For the example: prior odds are 1:999. The likelihood ratio is 0.99 / 0.01 = 99. So the posterior odds are 99:999, which is about 1:10 — the same 9%.
Two useful habits fall out of this form. A likelihood ratio near 1 means the evidence barely moves your belief, however dramatic it sounds. And updates chain by multiplication, so several independent pieces of evidence multiply their ratios together — which is exactly what Naive Bayes does with words in a document.
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.
The usual criticism of Bayesian methods is that the prior is subjective — two people can start from different beliefs and reach different conclusions from the same data.
Three responses, all practical:
Data overwhelms the prior. With enough evidence, any two reasonable priors converge to the same posterior. Disagreement only persists when the data is thin — which is exactly when honesty about prior assumptions is most valuable.
The alternative is a hidden prior. Choosing a model, a feature set and a regularisation strength are all prior assumptions. Bayesian methods write them down.
Weak priors exist. When you genuinely know little, a wide, uninformative prior lets the data do nearly all the work.
Where priors earn their keep is small data. A conversion rate estimated from 3 clicks in 10 visits is 30% by the naive calculation; with a sensible prior from historical rates it comes out far more plausibly, and with an honest interval around it.
A word appears in 8% of spam emails and 1% of legitimate ones. Spam is 40% of all mail. An email contains the word — how likely is it to be spam?
One word moved the belief from 40% to 84%. A second independent word would multiply the odds again — which is how a filter reaches near-certainty from a handful of weak signals, and why removing one incriminating word rarely fools it.
What is the difference between P(A|B) and P(B|A)? Everything. The probability of a positive test given the disease is not the probability of the disease given a positive test, and confusing the two is the error the medical example above is built on.
Where does the prior come from? Historical data, domain knowledge, or a deliberately weak default. It should be stated, not hidden.
Is Bayesian statistics better than frequentist? They answer different questions. Bayesian methods give the probability of a hypothesis given the data; frequentist methods give the probability of the data given a hypothesis. The second is what a p-value is, and it is routinely misread as the first.
Why is Naive Bayes called naive? Because it assumes all features are independent given the class, which is almost never true — and works anyway for ranking.
How do I compute P(B) in practice? By summing over all the ways B can happen: P(B) = Σ P(B|Aᵢ)P(Aᵢ). In classification it is the same for every class, so it can be ignored while ranking.
What is a conjugate prior? A prior whose posterior has the same mathematical form, which makes the update a closed-form calculation rather than a simulation. Beta with binomial is the classic pair.
Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.
What does this module say about “What this is”?
Bayes' theorem takes a prior belief and revises it in light of new evidence. It is the mathematics of changing your mind correctly.
What does this module say about “Count People, Not Percentages”?
The grid shows 10,000 people, one square each. With a 1% base rate and a 99% accurate test:
What does this module say about “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:
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.