Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #320

Conditional Probability

Conditional probability answers "given that B happened, how likely is A?" — it's the difference between an event's probability in general, and its probability once you already have some relevant information.

Formula

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

\(P(A \mid B)\) is read "probability of A given B." \(P(A \cap B)\) is the probability both A and B happen together. \(P(B)\) is the probability of B on its own — this formula effectively "zooms in" on only the cases where B is true, then asks what fraction of those also have A.

Visual Intuition

A B A∩B

P(A|B) asks: of everything inside circle B, what fraction also falls inside circle A?

Numerical Example

Out of 100 emails: 30 contain the word "free" (event B), and of those, 24 are spam (event A∩B). Also, 40 emails total are spam.

\[ P(\text{spam} \mid \text{"free"}) = \frac{P(\text{spam} \cap \text{"free"})}{P(\text{"free"})} = \frac{24/100}{30/100} = \frac{24}{30} = 0.8 \]

Notice this (0.8) is very different from the overall \(P(\text{spam}) = 40/100 = 0.4\) — seeing the word "free" substantially raises the probability of spam. This gap between the conditional and unconditional probability is exactly the signal a classifier like Naive Bayes learns to exploit.

total_emails = 100
contains_free = 30
spam_and_free = 24

p_spam_given_free = spam_and_free / contains_free
print(p_spam_given_free)   # 0.8

Independence — The Special Case Where Conditioning Changes Nothing

\[ \text{A and B are independent if and only if } P(A \mid B) = P(A) \]

If knowing B happened doesn't change the probability of A at all, they're independent — this is the assumption Naive Bayes makes between features (hence "naive"), even though it's rarely exactly true in real data.

Common Mistakes

  • Confusing \(P(A\mid B)\) with \(P(B\mid A)\) — these are generally different numbers (this is the same mix-up covered in Bayes' Theorem).
  • Assuming conditioning always changes the probability — for genuinely independent events, it doesn't, by definition.

Interview Relevance

Q: "How is conditional probability different from joint probability?" Joint probability \(P(A \cap B)\) is the chance both happen out of all outcomes; conditional probability \(P(A\mid B)\) restricts the "universe" to only outcomes where B already happened, then asks what fraction of those also have A.

Practice Question

Out of 200 loan applicants, 50 have a credit score below 600, and of those, 30 defaulted. What is \(P(\text{default} \mid \text{credit score} < 600)\)?

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →