Course contentsShow
← Computer Science
Lesson 118 of 2,8723. Probability for Computer ScienceFree lesson

Bayes' Theorem

Apply Bayes' theorem to update probabilities based on new evidence or information.

Bayes' Theorem

What You'll Learn

You'll learn how to use Bayes' Theorem to reverse conditional probabilities and update your beliefs when new evidence appears.

The Core Idea

You already know conditional probability: P(A|B) tells you the probability of A given B happened. But what if you know P(B|A) and need P(A|B) instead? That's where Bayes' Theorem shines.

Bayes' Theorem states:

P(A|B) = [P(B|A) × P(A)] / P(B)

Think of it as flipping conditional probabilities. It answers: "If I observe B, what's the updated probability that A caused it?"

Why This Matters

Imagine you're building spam detection software. You want P(spam|word) — the probability an email is spam given it contains a certain word. But it's easier to measure P(word|spam) — how often that word appears in known spam. Bayes' Theorem lets you flip this around using what you already know:

  • P(word|spam): Likelihood the word appears in spam
  • P(spam): Overall rate of spam emails (prior probability)
  • P(word): Overall rate of the word appearing

Plug these into the formula to get P(spam|word), the probability you actually need.

Real-World Flow

  1. Start with a prior probability P(A) — your initial belief before seeing evidence
  2. Observe new evidence B
  3. Use Bayes' Theorem to compute the posterior probability P(A|B) — your updated belief

You're essentially asking: "Now that I've seen B, how should I revise my belief about A?"

Key Takeaway: Bayes' Theorem flips conditional probabilities, letting you update beliefs about causes when you observe effects — essential for spam filters, medical diagnosis, and machine learning.