Math for CS and ML · 15 min

Bayes' rule: a 90% test that is usually wrong

Draw everyone as a square to see why the prior matters as much as the evidence, and how to update twice.

01Why it matters

A 90% accurate test says you're sick. Are you?

A disease affects 1 person in 100. A test catches 90% of people who have it, and wrongly flags 9% of people who don't. You test positive. What is the chance you have the disease?

Most people, including many doctors in published studies, answer "about 90%". The true answer is about 9%. This lesson shows why, with a picture that makes the answer obvious instead of surprising.

02Key parts

The pieces you will see

H and E
H is the hypothesis ("has the disease"); E is the evidence ("tests positive").
prior P(H)
How likely H is before you see any evidence: here 1%.
likelihoods
P(E∣H)P(E \mid H), how often H produces the evidence (90%), and P(E∣¬H)P(E \mid \neg H), how often it appears without H (9%).
posterior P(H | E)
How likely H is once you know E happened. This is what you want.

03See it work

Draw everyone as a square

Split 1000 people by who has the disease, then shade who tests positive. Once you know the test was positive, only the bottom strip is left.

The sick column is a sliver, 10 people out of 1000. Even though the test catches 9 of them, it also flags 9% of the 990 healthy people, about 89. So among the 98 positives, only 9 are sick:

P(H∣E)=P(E∣H) P(H)P(E)=0.9×0.010.9×0.01+0.09×0.99≈0.09P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)} = \frac{0.9 \times 0.01}{0.9 \times 0.01 + 0.09 \times 0.99} \approx 0.09

04Predict

Your turn: count the people

This time the condition affects 30% of people. Predict each count before you step, then the final chance.

Make 4 predictions: step forward and answer each question before the next step plays.

0 of 4 made

05Try it

Move the dividers

Drag the divider (the prior) and the tops of the two shaded strips (the hit rate and the false alarm rate). Try to answer:

  • How common must the disease be before a positive test means "more likely than not"?
  • Which helps more for a rare disease: catching more of the sick, or flagging fewer of the healthy?
  • What happens when both strips are the same height?

06Check yourself

Check yourself

  1. Question 1 of 4

    In a group of 1000, 50 have a condition. A test flags 80% of them and 10% of the other 950. Roughly how many positives are there?

    Your answer comes back in Review in a few days, so it sticks.

  2. Question 2 of 4

    In that group, what is the chance that someone who tests positive has the condition?

  3. Question 3 of 4

    Evidence is equally likely with or without H. What does seeing it do to P(H)?

  4. Question 4 of 4

    A second, independent positive test arrives. How do you update?

07Explain it back

Say it in your own words

Why can a positive result from an accurate test still leave a rare disease unlikely?

08Recap

What to remember

  • Draw the whole population, split by the prior, then shade the evidence in each part.
  • P(H∣E)P(H \mid E) is H's share of the evidence: P(E∣H)P(H)/P(E)P(E \mid H)P(H) / P(E).
  • Rare hypotheses need very clean evidence: false alarms from the large majority swamp the true hits.
  • Updates chain: today's posterior is tomorrow's prior. Naive Bayes spam filters do this word by word.
Back to path