Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Bayes' theorem is the single most important formula in applied probability. It tells you how to invert a conditional — from , which you usually have, to , which you usually want. Every modern ML model that does inference is using a Bayes update somewhere. The infamous failure mode is base-rate neglect: you read 'this test is 99% accurate' and conclude that a positive result means 99% chance of disease, when the actual posterior can be under 10% if the disease is rare. One worked Bayes calculation immunises you for life.
Bayes' theorem rewrites the conditional in the other direction by combining the prior , the likelihood , and the marginal evidence — typically computed via the law of total probability. The posterior is proportional to prior times likelihood.
Use these three in order. Each builds on the one before.
In one paragraph, state Bayes' theorem in plain English using the medical-test example. Be explicit about the role of the prior, the likelihood, and why the answer is so different from people's gut intuition.
Walk me step by step through deriving Bayes' theorem from the definition of conditional probability and the law of total probability. Then derive the odds form: $\frac{P(H \mid E)}{P(H^c \mid E)} = \frac{P(E \mid H)}{P(E \mid H^c)} \cdot \frac{P(H)}{P(H^c)}$, and explain why the odds form is easier to update with.
I run a fraud detector that flags 1 in 1000 transactions, with 95% sensitivity and 99% specificity. Of the *flagged* transactions, what fraction are actually fraudulent? Now suppose I retrain to push sensitivity to 99.9% but specificity drops to 98%. Did the precision get better or worse? Show the calculation and explain the trade-off.
// main.go — run: go run main.go
package main
import "fmt"
func main() {
// Classic medical-test problem.
// Prior: 1% of population has the disease.
// Test: 99% sensitivity (P(+ | D)), 95% specificity (P(- | not D) = 0.95, so P(+ | not D) = 0.05).
pD := 0.01
pPosD := 0.99
pPosNotD := 0.05
pPos := pPosD*pD + pPosNotD*(1-pD)
pDGivenPos := pPosD * pD / pPos
fmt.Printf("P(positive) = %.4f\n", pPos)
fmt.Printf("P(disease | +) = %.4f\n", pDGivenPos) // ~ 0.167
fmt.Printf("P(no disease | +) = %.4f\n", 1-pDGivenPos)
}go run main.go