Skip to the workspace
Pebellslearn by building
Probability  ›  Lesson

Bayes' Theorem

Bayes Theorem 15 minBayes' theorem reverses a conditional probability by weighting the likelihood with the prior and dividing by how common the evidence is.

machine learning / Bayes' Theorem

Explore each scene at your own pace.

01 · The rule

The rule

Bayes' Theorem

The agency buys a fake-listing detector. It catches 90% of fake listings and wrongly flags only 10% of genuine ones. A listing gets flagged. Is it 90% likely to be fake? Most people say yes, and most people are badly wrong. Bayes' theorem shows why.

The rule

Reverse a condition: likelihood times prior, divided by evidence.

The detector tells you P(flag∣fake)P(\text{flag} \mid \text{fake}). You want the reverse, P(fake∣flag)P(\text{fake} \mid \text{flag}). Bayes' theorem connects them:

P(A∣B)=P(B∣A) P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)}
  • Prior P(A)P(A): how common the cause is before any evidence. Here 5% of listings are fake.
  • Likelihood P(B∣A)P(B \mid A): how often the evidence appears when the cause is true. Here 0.9.
  • Evidence P(B)P(B): how often the evidence appears at all, from any cause.
  • Posterior P(A∣B)P(A \mid B): the updated belief after seeing the evidence.

Check it on last lesson's 20 flats: P(near∣fast)=0.75×0.4/0.6=0.5P(\text{near} \mid \text{fast}) = 0.75 \times 0.4 / 0.6 = 0.5, the same answer the table gave by counting.

Bayes' theorem also chains. If a second, independent check flags the same listing, today's posterior of 0.32 becomes the prior for that update, and the belief climbs again. Learning from evidence is repeated Bayesian updating.

A naive Bayes classifier uses this rule directly: it multiplies the likelihoods of each feature (each word in a listing, say) with the prior for each class, and picks the class with the higher result.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.