Bayes' rule: updating on evidence
Turn P(evidence | cause) into P(cause | evidence). The prior matters more than intuition says: a good test for a rare condition mostly finds false alarms.
1. The idea
Bayes' rule turns a conditional probability around. Often you know P(evidence | cause), such as how likely a positive test is if someone has a condition, but you want P(cause | evidence): how likely the condition is, given a positive test. Bayes' rule connects the two: P(A | B) = P(B | A) P(A) / P(B).
The P(A) in it, the prior, is what you believed before the evidence, and it matters enormously. If a condition affects 1 person in 100, a test that catches 90% of cases and gives false alarms only 5% of the time still produces mostly false alarms: out of 1000 people, 9 true positives against about 50 false ones.
In machine learning the same rule reads posterior ∝ likelihood × prior: p(θ | data) ∝ p(data | θ) p(θ). Maximum likelihood ignores the prior. Adding one, for example a belief that weights are probably small, gives regularization; in these terms, weight decay is a prior.
2. Try it: a thousand people, one test
Blue squares have the condition; red outlines tested positive. Make the condition rarer and watch the share of positives that are real collapse, then see which slider rescues it.
3. The math
4. The code (python)
def posterior(prior, sensitivity, false_alarm):
evidence = sensitivity * prior + false_alarm * (1 - prior)
return sensitivity * prior / evidence
print(round(posterior(0.01, 0.9, 0.05), 3)) # 0.154
print(round(posterior(0.10, 0.9, 0.05), 3)) # 0.667
print(round(posterior(0.01, 0.99, 0.05), 3)) # 0.167
print(round(posterior(0.01, 0.9, 0.005), 3)) # 0.6455. You’ll see this in
6. Check yourself
Finished this chapter?
What changed in ML architectures this week
New models worth knowing, benchmark moves, and one architecture explained in plain words. Free, once a week, unsubscribe anytime.