Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Understanding Conditional Probability & Bayes' Theorem | Probability & Statistics
Mathematics for Data Science

bookUnderstanding Conditional Probability & Bayes' Theorem

Today, we're going to explore one of the most powerful concepts in probability and data science: Bayes' Theorem and Conditional Probability.
These tools help us update our beliefs about uncertain events when new information becomes available.

Conditional Probability

Conditional probability measures the chance of an event happening given that another event has already occurred.

Formula:

P(AB)=P(AB)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}

where:

  • P(AB)P(A \mid B) means "the probability of A given B";
  • P(AB)P(A \cap B) is the probability that both A and B happen;
  • P(B)P(B) is the probability that B happens (must be > 0).

Example 1: Conditional Probability — Weather and Traffic

Suppose:

  • Event A: "I am late to work";
  • Event B: "It is raining".

Given:

  • P(AB)=0.10P(A \cap B) = 0.10 (10% chance it rains AND I am late);
  • P(B)=0.20P(B) = 0.20 (20% chance it rains on any day).

Then:

P(AB)=P(AB)P(B)=0.100.20=0.5P(A \mid B) = \frac{P(A \cap B)}{P(B)} = \frac{0.10}{0.20} = 0.5

Interpretation:
If it is raining, there's a 50% chance I will be late to work.

Bayes' Theorem

Bayes' Theorem helps us find P(AB)P(A \mid B) when it's hard to measure directly, by relating it to P(BA)P(B \mid A).

Formula:

P(AB)=P(BA)P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}

Step-by-Step Breakdown

Step 1: Understanding P(AB)P(A \mid B)
This reads as "the probability of A given B";

Example: If A = "having a disease" and B = "testing positive", then P(AB)P(A \mid B) asks:
Given a positive test, what are the chances the person actually has the disease?

Step 2: Numerator = P(BA)P(A)P(B \mid A) \cdot P(A)

  • P(BA)P(B \mid A) = probability of testing positive if you have the disease (test sensitivity);
  • P(A)P(A) = prior probability of A (disease prevalence).

Step 3: Denominator = P(B)P(B)
This is the total probability that B happens (testing positive), from both true positives and false positives.

Expanded:

P(B)=P(BA)P(A)+P(B¬A)P(¬A)P(B) = P(B \mid A)P(A) + P(B \mid \neg A)P(\neg A)

Where:

  • P(B¬A)P(B \mid \neg A) = false positive rate;
  • P(¬A)P(\neg A) = probability of not having the disease.

Bayes' Theorem — Medical Test

Suppose:

  • Event A: "Having a disease";
  • Event B: "Testing positive".

Given:

  • Disease prevalence: P(A)=0.01P(A) = 0.01;
  • Sensitivity: P(BA)=0.99P(B \mid A) = 0.99;
  • False positive rate: P(B¬A)=0.05P(B \mid \neg A) = 0.05.

Step 1: Calculate total probability of testing positive

P(B)=(0.99)(0.01)+(0.05)(0.99)=0.0594P(B) = (0.99)(0.01) + (0.05)(0.99) = 0.0594

Step 2: Apply Bayes' Theorem

P(AB)=0.990.010.05940.167P(A \mid B) = \frac{0.99 \cdot 0.01}{0.0594} \approx 0.167

Interpretation:
Even if you test positive, there's only about a 16.7% chance you actually have the disease — because the disease is rare and there are false positives.

Key Takeaways

  • Conditional probability finds the chance of A happening when we know B has occurred;
  • Bayes' Theorem flips conditional probabilities, letting us update beliefs when direct measurement is hard;
  • Both concepts are essential in data science, machine learning, medical testing, and decision-making.
Note
Note

Think of Bayes' Theorem as: "The probability of A given B equals the chance of B happening if A is true, multiplied by how likely A is, divided by how likely B is overall."

1. What does conditional probability represent?

2. Which is the correct formula for conditional probability?

3. If P(AB)=0.3P(A \cap B) = 0.3 and P(B)=0.5P(B) = 0.5, what is P(AB)P(A \mid B)?

4. In Bayes' Theorem, what does P(BA)P(B \mid A) represent?

5. In Bayes' Theorem, what role does P(B)P(B) play?

6. Why is Bayes' Theorem useful in real-world problems like medical testing or spam filtering?

question mark

What does conditional probability represent?

Select the correct answer

question mark

Which is the correct formula for conditional probability?

Select the correct answer

question mark

If P(AB)=0.3P(A \cap B) = 0.3 and P(B)=0.5P(B) = 0.5, what is P(AB)P(A \mid B)?

Select the correct answer

question mark

In Bayes' Theorem, what does P(BA)P(B \mid A) represent?

Select the correct answer

question mark

In Bayes' Theorem, what role does P(B)P(B) play?

Select the correct answer

question mark

Why is Bayes' Theorem useful in real-world problems like medical testing or spam filtering?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Awesome!

Completion rate improved to 1.89

bookUnderstanding Conditional Probability & Bayes' Theorem

Desliza para mostrar el menú

Today, we're going to explore one of the most powerful concepts in probability and data science: Bayes' Theorem and Conditional Probability.
These tools help us update our beliefs about uncertain events when new information becomes available.

Conditional Probability

Conditional probability measures the chance of an event happening given that another event has already occurred.

Formula:

P(AB)=P(AB)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}

where:

  • P(AB)P(A \mid B) means "the probability of A given B";
  • P(AB)P(A \cap B) is the probability that both A and B happen;
  • P(B)P(B) is the probability that B happens (must be > 0).

Example 1: Conditional Probability — Weather and Traffic

Suppose:

  • Event A: "I am late to work";
  • Event B: "It is raining".

Given:

  • P(AB)=0.10P(A \cap B) = 0.10 (10% chance it rains AND I am late);
  • P(B)=0.20P(B) = 0.20 (20% chance it rains on any day).

Then:

P(AB)=P(AB)P(B)=0.100.20=0.5P(A \mid B) = \frac{P(A \cap B)}{P(B)} = \frac{0.10}{0.20} = 0.5

Interpretation:
If it is raining, there's a 50% chance I will be late to work.

Bayes' Theorem

Bayes' Theorem helps us find P(AB)P(A \mid B) when it's hard to measure directly, by relating it to P(BA)P(B \mid A).

Formula:

P(AB)=P(BA)P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}

Step-by-Step Breakdown

Step 1: Understanding P(AB)P(A \mid B)
This reads as "the probability of A given B";

Example: If A = "having a disease" and B = "testing positive", then P(AB)P(A \mid B) asks:
Given a positive test, what are the chances the person actually has the disease?

Step 2: Numerator = P(BA)P(A)P(B \mid A) \cdot P(A)

  • P(BA)P(B \mid A) = probability of testing positive if you have the disease (test sensitivity);
  • P(A)P(A) = prior probability of A (disease prevalence).

Step 3: Denominator = P(B)P(B)
This is the total probability that B happens (testing positive), from both true positives and false positives.

Expanded:

P(B)=P(BA)P(A)+P(B¬A)P(¬A)P(B) = P(B \mid A)P(A) + P(B \mid \neg A)P(\neg A)

Where:

  • P(B¬A)P(B \mid \neg A) = false positive rate;
  • P(¬A)P(\neg A) = probability of not having the disease.

Bayes' Theorem — Medical Test

Suppose:

  • Event A: "Having a disease";
  • Event B: "Testing positive".

Given:

  • Disease prevalence: P(A)=0.01P(A) = 0.01;
  • Sensitivity: P(BA)=0.99P(B \mid A) = 0.99;
  • False positive rate: P(B¬A)=0.05P(B \mid \neg A) = 0.05.

Step 1: Calculate total probability of testing positive

P(B)=(0.99)(0.01)+(0.05)(0.99)=0.0594P(B) = (0.99)(0.01) + (0.05)(0.99) = 0.0594

Step 2: Apply Bayes' Theorem

P(AB)=0.990.010.05940.167P(A \mid B) = \frac{0.99 \cdot 0.01}{0.0594} \approx 0.167

Interpretation:
Even if you test positive, there's only about a 16.7% chance you actually have the disease — because the disease is rare and there are false positives.

Key Takeaways

  • Conditional probability finds the chance of A happening when we know B has occurred;
  • Bayes' Theorem flips conditional probabilities, letting us update beliefs when direct measurement is hard;
  • Both concepts are essential in data science, machine learning, medical testing, and decision-making.
Note
Note

Think of Bayes' Theorem as: "The probability of A given B equals the chance of B happening if A is true, multiplied by how likely A is, divided by how likely B is overall."

1. What does conditional probability represent?

2. Which is the correct formula for conditional probability?

3. If P(AB)=0.3P(A \cap B) = 0.3 and P(B)=0.5P(B) = 0.5, what is P(AB)P(A \mid B)?

4. In Bayes' Theorem, what does P(BA)P(B \mid A) represent?

5. In Bayes' Theorem, what role does P(B)P(B) play?

6. Why is Bayes' Theorem useful in real-world problems like medical testing or spam filtering?

question mark

What does conditional probability represent?

Select the correct answer

question mark

Which is the correct formula for conditional probability?

Select the correct answer

question mark

If P(AB)=0.3P(A \cap B) = 0.3 and P(B)=0.5P(B) = 0.5, what is P(AB)P(A \mid B)?

Select the correct answer

question mark

In Bayes' Theorem, what does P(BA)P(B \mid A) represent?

Select the correct answer

question mark

In Bayes' Theorem, what role does P(B)P(B) play?

Select the correct answer

question mark

Why is Bayes' Theorem useful in real-world problems like medical testing or spam filtering?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 3
some-alt