Conditional probability, Bayes and base rates
A detector catches 90% of faults and false-alarms only 5% of the time. A part is flagged. Is it probably faulty?
About 45 min · 3 goals · Checked by automated tests
1.Why should I care?
Perception systems turn evidence into beliefs: 'a pedestrian is probably there', 'this part is probably faulty'. Bayes' rule is the arithmetic of doing that honestly, and forgetting the base rate is one of the most common reasoning errors made by people and machines alike.
- ◇ Use event notation and compute conditional probabilities from a frequency table.
- ◇ Derive Bayes' rule from counts and apply it with a base rate.
- ◇ Explain why a rare condition makes even a good detector's alarms mostly false.
2.Predict
1% of parts are faulty. The detector flags 90% of faulty parts and 5% of good ones. A part is flagged. Roughly how likely is it to be faulty?
Guess first. Being wrong here is how the surprise works.
3.Discover
Start at base rate 1%, sensitivity 90%, false positives 5%. Read the counts in each branch and check the answer by hand. Then raise the base rate to 20%. Then go back to 1% and halve the false-positive rate. Which change helps the flags most? Finally, try 'tested a second time'.
Loading the interactive…
Can't use the interactive? Read a description instead
The base-rate tree splits 10,000 parts by base rate into faulty and good, then each into flagged and not flagged. At base rate 1%, sensitivity 90% and false positives 5%: 100 faulty (90 flagged, 10 missed) and 9,900 good (495 flagged, 9,405 passed). P(faulty | flagged) = 90 ÷ 585 ≈ 15.4%. A second independent flag raises it to about 77%.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
Out of 1000 parts, 20 are faulty and flagged and 60 are good but flagged. What is P(faulty | flagged), as a percentage?
5.Watch
→ Watch for the idea of a test's 'Bayes factor': how much a positive result multiplies the odds, regardless of the base rate you start from.
Why a very accurate test can still be wrong most of the time when the condition is rare: the base-rate effect your fault detector faces.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
6.Understand
Events and conditions
An event is something that does or doesn't happen: 'faulty', 'flagged'. P(F) is its probability over all parts. A conditional probability P(F | +) restricts attention to the cases where + happened. Reading '|' as 'among those that' keeps it straight: the share faulty among those that were flagged.
Count, don't juggle formulas
The safest way to apply Bayes' rule is a frequency tree: pick a population (10,000 is convenient), split it by the base rate, then split each branch by the detector's rates, and finally compare the branches that match the evidence. The formula and the counts give the same answer; the counts are harder to get wrong.
Base rates rule
When the condition is rare, false alarms from the huge 'good' group can outnumber real detections from the tiny 'faulty' group. Two remedies: reduce the false-positive rate, or confirm a flag with a second, independent check, using the first answer as the new base rate. Independence is an assumption: two sensors fooled by the same glare are not independent.
Explain it another way
If you hear hoofbeats in a British town, think horses, not zebras: even if a sound is 'zebra-like', zebras are so rare there that horses are still the better bet.
P(F | +) = P(+ | F)P(F) / [P(+ | F)P(F) + P(+ | ¬F)P(¬F)]. In odds form: posterior odds = prior odds × likelihood ratio, where the likelihood ratio is P(+ | F)/P(+ | ¬F) = 0.9/0.05 = 18 for this detector.
Prior odds 1:99, times 18, gives 18:99 ≈ 0.18, a probability of 18/117 ≈ 15.4%. A second independent flag multiplies again: 324:99, about 77%.
Sensor fusion and robot localisation are repeated Bayesian updates: each new reading multiplies the robot's belief about where it is, then motion spreads that belief out again.
Derivation: Bayes' rule from a frequency table
Events: F = 'part is faulty', + = 'detector flags it'. P(A | B) means 'the probability of A among the cases where B happened'.
Imagine N parts. Faulty: N·P(F). Of those, flagged: N·P(F)·P(+ | F).
Good: N·(1 − P(F)). Of those, flagged: N·(1 − P(F))·P(+ | not F).
Among all flagged parts, the share that are faulty is P(F | +) = N·P(F)·P(+ | F) ÷ [N·P(F)·P(+ | F) + N·(1 − P(F))·P(+ | not F)].
N cancels. The denominator is P(+), the overall chance of a flag. So P(F | +) = P(+ | F)·P(F) ÷ P(+): Bayes' rule.
Numbers: P(F) = 0.01, P(+ | F) = 0.9, P(+ | not F) = 0.05: P(F | +) = 0.009 ÷ (0.009 + 0.0495) = 0.009 ÷ 0.0585 ≈ 0.154.
P(F | +) and P(+ | F) are different questions: 15% versus 90%. Confusing them is called the base-rate fallacy.
Worked example 1
Base rate 10%, sensitivity 80%, false positives 10%. P(faulty | flagged)?
Out of 1000: 100 faulty → 80 flagged; 900 good → 90 flagged. P = 80 ÷ 170 ≈ 47%.
Common mix-ups
- If a test is 95% accurate, a positive result is 95% likely to be right.
✓ That depends on the base rate. For rare conditions a positive can still be more likely wrong than right. - Two checks always multiply the evidence.
✓ Only if their errors are independent. Checks fooled by the same cause add little.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
1% of parts on a line are faulty. A camera check flags 99% of faulty parts and wrongly flags 1% of good parts. A part is flagged. What is the probability, as a percentage, that it is really faulty?
Practice 3 · a fresh version every time
2% of parts on a line are faulty. A camera check flags 95% of faulty parts and wrongly flags 5% of good parts. A part is flagged. What is the probability, as a percentage, that it is really faulty?
Practice 4
P(flagged | faulty) = 0.95. Which statement follows?
Practice 5
Base rate 0.5%, sensitivity 95%, false positives 4%. Which change most raises P(faulty | flagged)?
8.Apply it
BUILD 003 Level 4 asks how often a majority vote of three sensors is wrong when each is wrong 10% of the time. Work it out with a probability tree, then use Bayes' rule to find P(part is really red | majority says red) for a line where 30% of parts are red. Say which assumption could fail.
9.Reflect
Concepts: Conditional probability and Bayes' rule · Evaluation metrics