Bayes: The Medical Test
Why positives mislead.
A disease affects one percent of people. A test catches ninety nine percent of sick people. But it also wrongly says positive for five percent of healthy people. You test positive. What's the chance you're sick? Pause and guess.

- 1% have the disease
- Test catches 99%
- 5% false positives
A million people
Instead of a formula, let's simulate a million people. One percent are sick. Sick people test positive ninety nine percent of the time, and healthy people five percent of the time. Then we look only at the people who tested positive. Run it. Only about seventeen percent of them are sick.
import numpy as np
rng = np.random.default_rng(0)
n = 1_000_000
sick = rng.random(n) < 0.01
positive = np.where(sick, rng.random(n) < 0.99, rng.random(n) < 0.05)
print("positives:", positive.sum())
print("P(sick | positive):", sick[positive].mean().round(3))positives: 59176 P(sick | positive): 0.167
Why so low?
Because healthy people vastly outnumber sick people. Five percent of nearly a million healthy people is about fifty thousand false alarms. That swamps the roughly ten thousand true positives. When something is rare, even a good test gives mostly false positives. In machine learning, the same thing happens with rare classes, like fraud.
| key | value |
|---|---|
| True positives | about 10,000 |
| False positives | about 50,000 |
| So | most positives are healthy |
| Lesson | rare events need care |
Summary
When a condition is rare, most positive results are false alarms. Always consider the base rate, the prior. Next, using Bayes to catch spam.
Key takeaways- Simulate to check
- Base rates matter
- Rare means many false alarms