ailiteracynepal 🇳🇵
Text size

Chapter 03 · Section II · 18 min read

The Bayes rule

A single equation that explains why a rare-disease test with 95% accuracy mostly produces false positives — and what to do about it.

Bayes’ rule is the single most useful piece of mathematics in this course. It tells you how to update a belief when new evidence arrives.

It is also the source of one of the most counter-intuitive results in all of statistics: that a 95% accurate test for a rare disease, applied to a healthy person who tests positive, is more often wrong than right. Most people guess that a positive result means a 95% chance of having the disease. The correct answer is closer to 2%. Bayes’ rule is the bookkeeping that gets you there.

The setup: prior, likelihood, posterior

Bayes’ rule has three ingredients. Learn the words and the rest is arithmetic.

  • Prior. Your belief about the world before you see the new evidence. “What fraction of Kathmandu residents have this rare disease?”
  • Likelihood. The probability of seeing the evidence given the hypothesis is true. “If a person has the disease, how likely is the test to be positive?” (Sensitivity.) “If they don’t, how likely is the test to be positive anyway?” (False positive rate.)
  • Posterior. Your updated belief after the evidence. “Given that this person tested positive, what is the probability they actually have the disease?”

Bayes’ rule is the rule for getting from prior + likelihood to posterior. We will not write the algebra; we will compute it.

A worked example: rare disease in Kathmandu

Imagine a disease affects 1 in 10,000 people in Kathmandu. A new test for it has the following properties:

  • If you have the disease, the test is positive 95% of the time.
  • If you don’t have the disease, the test is positive 5% of the time (false positives).

You test positive. What is the probability you actually have the disease?

The trick that makes Bayes’ rule easy is to count people, not multiply fractions. Imagine 1,000,000 random Kathmandu residents lining up to take the test.

Step 1 — split by disease status.

  • Have disease: 1,000,000 ÷ 10,000 = 100 people.
  • Healthy: 999,900 people.

Step 2 — count how many in each group test positive.

  • Have disease, test positive: 100 × 0.95 = 95 people.
  • Healthy, test positive: 999,900 × 0.05 = 49,995 people.

Step 3 — among those who tested positive, what fraction actually have the disease?

  • Total positives: 95 + 49,995 = 50,090.
  • Of those, the actually-sick: 95.
  • Fraction: 95 ÷ 50,090 ≈ 0.0019, or about 0.2%.

A positive result on a “95% accurate” test means you have a 0.2% chance of actually having the disease. Almost all positive results — 49,995 out of 50,090 — are false positives.

What changed when the test result came in?

Before the test, your prior probability of disease was 100 ÷ 1,000,000 = 0.01%. After the test, your posterior is 0.2%.

That’s a twentyfold increase. The evidence moved your belief — that is exactly what Bayes’ rule is meant to do. It just moved it from “tiny” to “twenty-times-tiny,” not from “tiny” to “near-certain.”

The takeaway is not that the test is useless. The takeaway is that the test must be used in context. In screening, a positive result is a reason to run a more specific (and more expensive) confirmatory test — not to start treatment.

The same logic in AI systems

Replace “disease” with “fraud”, “test” with “fraud model”, and “Kathmandu residents” with “Khalti transactions.” The same arithmetic applies.

Genuine fraud is rare in Khalti’s transaction stream — perhaps 1 in 5,000 transactions. A model that catches 95% of fraud and flags 1% of legitimate transactions sounds excellent. But run the numbers:

  • Fraud, flagged: (1 / 5,000) × 0.95 ≈ 0.00019 per transaction.
  • Legitimate, flagged: (4,999 / 5,000) × 0.01 ≈ 0.00999 per transaction.

For every genuine fraud the model catches, it incorrectly flags about 50 legitimate transactions. The system cannot simply block flagged transactions — it has to challenge them, with an OTP or call, because the cost of locking out 50 honest users for every fraudster caught would be unacceptable.

This is why the fraud team’s choice of how to respond to a flag matters more than the model’s raw accuracy. The Bayes calculation tells you what kind of response makes sense.

Reading Bayes in newspapers

Three real-world examples of Bayes-shaped confusion:

  1. “DNA evidence has a one-in-a-million error rate.” True — but in a city of a million, that means one wrongly-implicated person walking around. If you test against an entire database, false matches are essentially guaranteed.

  2. “Airport security catches 99% of weapons.” Possibly true — but if only 1 in a million travellers carries a weapon, the alarm goes off vastly more often for innocent travellers than for armed ones.

  3. “AI tutor identified 80% of students at risk of dropping out.” If only 5% of students were actually at risk, the alerts are mostly false. Acting on the alerts as if they were verdicts will hurt the wrong students.

In all three, the underlying maths is identical: a low base rate combined with an imperfect test produces a flood of false positives. Once you can see it, you can spot it everywhere.

Check your understanding

Quick check

In Bayes' rule, the updated belief about a hypothesis after observing new evidence is called the:

Quick check

A test for a rare disease has 95% sensitivity and a 5% false-positive rate. Why might a positive result still mean the person is most likely healthy?

What comes next

We’ve seen Bayes’ rule once. The next section turns it into a working AI classifier — Naive Bayes — that for two decades was the workhorse of spam filtering and document classification. You can implement it in twenty lines of code. Most “AI” deployments in 2026 would be better served by it than by a large language model.