Home/Learn/Math for AI/Probability Rules & Conditional Probability

Probability Rules & Conditional Probability

Intermediate
Probability & Statistics

Probability quantifies uncertainty from 0 to 1; conditional probability P(A|B) updates that belief once you know something — the mechanism behind every model that predicts under uncertainty.

Overview

Machine learning is reasoning under uncertainty, and probability is its language. A probability is a number in [0,1]; the probabilities of all mutually exclusive outcomes sum to 1. Two rules do most of the work: the sum rule (probability of A or B) and the product rule (probability of A and B). The key concept is conditional probability, P(A|B) — the probability of A given that B has happened — because prediction is exactly this: P(label | features). Independence (when knowing B tells you nothing about A, so P(A|B)=P(A)) is the simplifying assumption behind the Naive Bayes classifier and shows up whenever we factorise complex joint distributions. Getting comfortable with "update the probability once you condition on evidence" is the mental move that unlocks Bayesian thinking and generative models.

Conditional probability from counts

P(A|B) = P(A and B) / P(B): restrict attention to the world where B is true, then ask how often A also holds. Estimating it from data is just filtered counting.

P(A|B) = P(A and B) / P(B) — conditioning on evidence
import numpy as np

# columns: [is_spam, has_word_free]
data = np.array([[1,1],[1,1],[1,0],[0,0],[0,1],[0,0],[0,0],[1,1]])
spam, free = data[:,0], data[:,1]

p_free = free.mean()
p_spam_and_free = ((spam==1) & (free==1)).mean()
p_spam_given_free = p_spam_and_free / p_free        # P(spam | free)
print(round(p_spam_given_free, 3))   # higher than base spam rate

Independence and the chain rule of probability

If events are independent, joint = product of marginals. Otherwise the chain rule factorises a joint into conditionals — the backbone of language models, which predict each token given the ones before.

Chain rule factorises a joint — how LLMs score sentences
import numpy as np

# Independent: P(A and B) = P(A) * P(B)
pA, pB = 0.3, 0.5
print("indep joint:", pA * pB)     # 0.15

# Chain rule (general): P(w1,w2,w3) = P(w1) P(w2|w1) P(w3|w1,w2)
# This is exactly how an LLM assigns probability to a sentence.
p = 0.4 * 0.6 * 0.7
print("sentence prob:", round(p, 3))

Key Points to Remember

  • 1A probability lies in [0,1]; exclusive outcomes sum to 1
  • 2Conditional P(A|B) = P(A and B) / P(B): belief updated by evidence
  • 3Prediction is conditional probability: P(label | features)
  • 4Independence lets joints factor into products; the chain rule factors them into conditionals (LLMs)

Interview Questions

Sign in to ask Aria
1

Define conditional probability and give the formula.

EasyAmazon
2

How does the chain rule of probability relate to language modelling?

HardGoogle
3

What does it mean for two events to be independent?

EasyInfosys

Ask Aria about Probability Rules & Conditional Probability

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…