TactivergeLite

Lite / Intelligent Robotic Systems / Week 26

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 · Full interactive version

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.

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?

  1. About 90%
  2. About 50%
  3. About 15%
Guess first, then reveal

Picture 10,000 parts: 100 faulty, 90 of them flagged; 9,900 good, 495 of them flagged. Of 585 flags only 90 are real: about 15%. The rare base rate swamps the detector's accuracy.

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'.

What the interactive shows (text version)

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%.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: 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.

“The medical test paradox, and redesigning Bayes' rule” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

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

Intuitive

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.

Technical

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.

Mathematical

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%.

Applied

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
  1. Events: F = 'part is faulty', + = 'detector flags it'. P(A | B) means 'the probability of A among the cases where B happened'.

  2. Imagine N parts. Faulty: N·P(F). Of those, flagged: N·P(F)·P(+ | F).

  3. Good: N·(1 − P(F)). Of those, flagged: N·(1 − P(F))·P(+ | not F).

  4. 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)].

  5. N cancels. The denominator is P(+), the overall chance of a flag. So P(F | +) = P(+ | F)·P(F) ÷ P(+): Bayes' rule.

  6. 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.

  7. 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

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

%

%

%

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)?

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.

Reflect

Explain the base-rate effect to someone who has never studied probability, using a frequency tree.

Write your answer on paper or in your own notes. Lite never stores what you write.

← Confusion matrices, precision and recallExpected value: deciding when you can't be sure →