Bayes' Theorem
The direction you can measure — a test's accuracy, P(positive given disease) — is rarely the one you want, P(disease given positive). Bayes is the single rule that turns one into the other, and the base-rate twist inside it is the most-tested idea in GATE probability.
What you'll learn
- Bayes as the inversion of a conditional: from P(E|H) to P(H|E)
- Prior, likelihood, evidence (the normaliser), and posterior
- Working a medical-test problem to a number (a real 2026 question)
- Why a positive test for a rare condition is usually a false alarm
Before you start
We ended the last lesson stuck on a flip. The factory told us the chance a part is defective given its machine, but the inspector wanted the machine given a defective part. A doctor’s test reports the chance of a positive result given the disease, yet the patient wants the disease given a positive result. The direction you can easily measure is hardly ever the direction you care about. Bayes’ theorem is the one rule that turns the conditional around.
The rule that flips a conditional
Let us build it from the multiplication rule you already have. The chance of both a
hypothesis H and some evidence E can be written two ways, depending on which you
condition on first:
P(H ∩ E) = P(E | H) · P(H) and P(H ∩ E) = P(H | E) · P(E)
Both equal the same P(H ∩ E), so set them equal and divide by P(E). Out drops
Bayes’ theorem — the wanted direction P(H | E) in terms of the measurable one
P(E | H):
Each piece has a plain name, and naming them now that the formula is in front of you makes Bayes feel less like algebra and more like updating a belief:
- the prior
P(H)— what you believed before the evidence, - the likelihood
P(E | H)— how well the hypothesis explains the evidence, - the evidence
P(E)— the total chance of seeingEat all, the denominator that keeps the answer a proper probability, - the posterior
P(H | E)— your updated belief after the evidence.
So Bayes reads as a sentence: your belief after seeing the evidence is your belief before, reweighted by how well the hypothesis accounts for what you saw. Drag the prior below and watch a flat starting belief reshape, flip by flip, into a confident posterior.
Flip a coin of unknown bias — watch belief sharpen
Your belief about the coin’s bias θ is a Beta(α, β). Each flip updates it: posterior = Beta(α + H, β + T).
Try No idea vs Believe fair, then flip ~50 times — with enough evidence the two posteriors converge. The prior fades; the data wins.
A worked example — a real 2026 question
A disease affects 30% of a population. A test detects it correctly 80% of the time, and gives a 10% false-positive rate on healthy people. A person tests positive. What is the chance they have the disease?
Lay out the four numbers, then put the total chance of a positive in the denominator — a positive can arrive two ways, from a sick person or a healthy one:
P(D) = 0.30, P(+|D) = 0.80, P(+|¬D) = 0.10, P(¬D) = 0.70
P(+|D)·P(D) 0.80 · 0.30 0.24
P(D|+) = ───────────────────────── = ───────────────────── = ────── ≈ 0.77
P(+|D)·P(D) + P(+|¬D)·P(¬D) 0.80·0.30 + 0.10·0.70 0.31
So about 0.77. This is GATE DA 2026, question 57, and 0.77 is the verified answer. The disease was common enough at 30% that a positive really is convincing.
When the base rate is tiny
Now turn the prior down and watch the whole answer collapse. Suppose the disease is
rare — only 1% of people have it — with a test that is 99% sensitive and has a
5% false-positive rate. Run the same recipe:
0.99 · 0.01 0.0099
P(D|+) = ───────────────────────── = ──────────────── ≈ 0.17
0.99·0.01 + 0.05·0.99 0.0594
A near-perfect test, a positive result, and yet only a 17% chance of actually
being ill. The reason is the base rate: when almost nobody has the disease, the
healthy millions produce more false positives than the sick few produce true ones.
Drag the prevalence slider and watch the posterior swing.
Why a 99%-accurate test still mostly catches healthy people
Each cell is one person. Drag the sliders — watch how false positives (healthy but tested positive) can outnumber true positives when the disease is rare.
A question to carry forward
So far each “hypothesis” was a single yes-or-no — sick or healthy, one machine or the other. Here is the thread onward: when there are several competing causes (three boxes a ball might come from, four machines a part might leave), the denominator simply grows one term per cause. How does the recipe stretch when the evidence could have come from many sources rather than two?
In one breath
- Bayes flips the conditional: from the measurable
P(E|H)to the wantedP(H|E)—P(H|E) = P(E|H)·P(H) / P(E). - Four parts: prior
P(H)(belief before), likelihoodP(E|H)(how wellHexplainsE), evidenceP(E)(the total-probability normaliser), posteriorP(H|E)(belief after). - The recipe (a guaranteed NAT): write prior × likelihood for every hypothesis, sum them for the denominator, divide the one you want. Disease 2026:
0.8·0.3 / (0.8·0.3 + 0.1·0.7) ≈ 0.77. - Base rates dominate: a rare condition makes most positives false alarms (
P(disease|+) ≈ 0.17at 1% prevalence) — never read the accuracyP(+|D)as the answerP(D|+). - It is just conditional + total probability, run backwards.
Practice
Quick check
Practice this in an interview
All questionsBayes' theorem updates a prior probability with new evidence: P(H|E) = P(E|H) P(H) / P(E). In disease testing, ignoring the low base rate (prior) makes a positive test look far more alarming than it really is — most positives are false positives when the disease is rare.
Conditional probability P(A|B) is the probability of A given that B has already occurred, computed as P(A and B) / P(B). It narrows the sample space to B, whereas joint probability P(A and B) lives in the full, unrestricted space.
The law of total probability decomposes P(A) over a mutually exclusive, exhaustive partition of the sample space: P(A) = Σ P(A|Bᵢ)·P(Bᵢ). It is the engine behind the Bayes denominator and any calculation where you want an overall rate built from segment-level rates.
If a feature value never appears with a given class in training, its conditional probability is zero, and since Naive Bayes multiplies probabilities, the whole posterior for that class becomes zero regardless of other evidence. The fix is Laplace (additive) smoothing, which adds a small count to every feature-class combination so no probability is ever exactly zero. This is essential for text where many words are unseen per class.