Course contentsShow
← Machine Learning and Deep Learning
Lesson 55 of 3,5381. Mathematical Foundations for Machine LearningFree lesson

Conditional Probability

Understand probability of events given other events and compute conditional probabilities.

Conditional Probability

What you'll learn: How to calculate the probability of an event when you already know another event has occurred.

The Core Idea

Conditional probability answers: "If I know X happened, how does that change the likelihood of Y?"

Think of it like this: the probability it's raining changes dramatically if you know the sky is cloudy. The cloudiness conditions your belief about rain.

Mathematically, the conditional probability of event A given event B is written as P(A|B) and calculated as:

P(A|B) = P(A and B) / P(B)

where P(B) > 0.

This reads: "The probability of A given B equals the probability of both A and B occurring, divided by the probability of B."

Why It Matters

You're essentially zooming in on a subset of the sample space. Once you know B happened, you're no longer considering all possible outcomes—only those where B is true. Within that restricted world, you ask how often A also occurs.

Simple Example

Imagine flipping two coins. The sample space has 4 outcomes: {HH, HT, TH, TT}.

  • P(both heads) = 1/4
  • P(first is heads) = 2/4 = 1/2

Question: If the first coin is heads, what's the probability both are heads?

P(both heads | first heads) = P(both heads AND first heads) / P(first heads) = (1/4) / (1/2) = 1/2

Knowing the first is heads cuts the possibilities from 4 to 2, and in one of those two, both are heads.

Key Takeaway: Conditional probability updates our beliefs about an event based on new information, calculated by focusing only on outcomes where the conditioning event occurs.