[MMD]
ML Probability & Statistics Chapter 1: Foundations of Probability and Probability Distributions
This post kicks off a series on Probability & Statistics. Machine learning models are, at their core, tools for reasoning under uncertainty. Every step — quantifying the uncertainty in a prediction, drawing inferences from data, evaluating model performance — rests on a foundation of probability and statistics.
This post is based on Week 1 of DeepLearning.AI's Mathematics for Machine Learning and Data Science — Probability & Statistics.
What You'll Learn#
- Probability basics — events, sample spaces, complements
- Addition rule — disjoint events vs. joint events
- Independence — the multiplication rule
- Conditional probability — probability given an event
- Bayes' theorem — prior and posterior probabilities
- Random variables and distributions — discrete and continuous
- Key distributions — binomial, Bernoulli, uniform, normal, chi-squared
Probability Basics#
What Is Probability?#
Probability is a number between 0 and 1 that expresses how likely an event is to occur.
Examples
- 3 out of 10 people play soccer:
- Rolling a 6 on a six-sided die:
- Getting heads twice in two coin flips:
Experiment: Any process that produces an uncertain outcome
Sample Space: The set of all possible outcomes
Complement#
The probability that event does not occur:
| Example | Calculation |
|---|---|
| Probability of not playing soccer | |
| Probability of not rolling a 6 | |
| Probability of not getting all heads in 3 flips |
Tip: When a probability is hard to compute directly, it's often easier to compute its complement instead.
Addition Rule — Disjoint Events#
Disjoint (Mutually Exclusive) Events: Events that cannot occur at the same time.
Example
- Probability of rolling an even number or a 5: , →
Addition Rule — Joint Events#
Joint Events: Events that can overlap. You must subtract the intersection to avoid double-counting.
Example — soccer (0.6), basketball (0.5), both (0.3):
Key point: You must first determine whether two events are disjoint or joint. Without knowing the intersection, the probability cannot be computed.
Independence#
Two events and are independent if the occurrence of one has no effect on the probability of the other.
Examples
- Getting heads 5 times in a row:
- Rolling a 6 ten times in a row:
The independence assumption greatly simplifies computation. The Naive Bayes classifier is built on exactly this assumption.
The Birthday Problem#
With 30 people in a room, what is the probability that at least two share a birthday?
It feels low intuitively, but the answer is actually over 70%.
Compute it using the complement:
Lesson: Our intuition about probability is often wrong. Always work it out with math.
Conditional Probability#
Concept#
Conditional probability: The probability that event occurs, given that event has already occurred.
Notation: ("the probability of A given B")
Example — two coin flips:
- = (if the first is H, only the second needs to be H)
- = 0 (HH is impossible if the first flip is T)
Product Rule#
The probability of the intersection of two dependent events:
Example — 40% of students play soccer, and 80% of those wear running shoes:
Independent vs. dependent: If events are related, they are dependent and conditional probability must be used.
Bayes' Theorem#
Formula#
| Term | Meaning |
|---|---|
| Prior — our baseline belief before seeing any evidence | |
| Posterior — our updated belief after observing evidence | |
| Likelihood — the probability of observing B given A | |
| Evidence — the overall probability of observing B |
Spam Email Example#
- 20% of emails are spam:
- 40% of spam emails contain "lottery":
- 10% of all emails contain "lottery":
The probability that an email containing "lottery" is spam is 80% — a dramatic update from the prior of 20%.
Naive Bayes#
When there are multiple features and we assume all features are independent:
It's called Naive because features are rarely truly independent in practice — but the assumption buys us:
- Dramatically simpler computation
- Good performance even with limited data
- Particular effectiveness in text classification (spam filtering)
Random Variables and Probability Distributions#
Random Variable#
A random variable is a variable that maps the outcome of an experiment to a numeric value.
| Type | Description | Examples |
|---|---|---|
| Discrete | A countable, finite set of values | Number of heads in coin flips, die roll result |
| Continuous | Infinitely many values within an interval | Height, temperature, waiting time |
Discrete Probability Distributions#
Binomial Distribution#
The probability of getting exactly successes in independent trials, each with success probability :
Binomial Coefficient:
The number of ways to choose items from without regard to order.
Example — the probability of rolling a 1 exactly 3 times in 5 die rolls:
Properties:
- → symmetric distribution
- → skewed distribution
- As grows large, converges to a normal distribution
Bernoulli Distribution#
A special case of the binomial distribution (). A single trial with only two outcomes: success or failure.
Example: The probability of rolling a 2 on a 4-sided die →
Bernoulli distribution = Binomial distribution
Continuous Probability Distributions#
Probability Density Function (PDF)#
For a continuous random variable, the probability of any single exact value is 0 (a point has no area). Instead, we compute the probability over an interval.
: Probability Density Function
Properties:
- (total area = 1)
Discrete: PMF (Probability Mass Function) ↔ Continuous: PDF (Probability Density Function)
Cumulative Distribution Function (CDF)#
Properties:
- Always starts at 0 and ends at 1
- Monotonically non-decreasing
- Discrete: staircase shape / Continuous: smooth curve
The CDF makes sampling from a distribution straightforward. Draw a value from a uniform distribution and apply the inverse CDF to get a sample from the desired distribution.
Uniform Distribution#
A distribution where every value in the interval has equal probability.
Parameters: (lower bound), (upper bound)
Example: If hold time is uniformly distributed between 0 and 5 minutes →
Normal (Gaussian) Distribution#
The most widely used distribution in machine learning. It appears frequently in natural phenomena (height, measurement error, etc.).
Parameters:
- (mu): mean — determines the location of the distribution
- (sigma): standard deviation — determines the spread of the distribution
Standard Normal Distribution: , →
Standardization:
Used to compare variables with different units and scales. This is the theoretical basis for feature scaling in machine learning.
The 68-95-99.7 Rule:
- About 68% of data falls within
- About 95% of data falls within
- About 99.7% of data falls within
Chi-Squared Distribution#
The distribution of the sum of squares of independent standard normal variables :
Parameter: (degrees of freedom)
Properties:
- Small : concentrated near 0, right-skewed
- Large : spreads out and becomes more symmetric
Machine learning applications:
- Hypothesis testing (independence tests, goodness-of-fit tests)
- Signal noise modeling (sum of squared noise)
Summary#
| Concept | Formula / Description |
|---|---|
| Basic probability | |
| Complement | |
| Disjoint union | |
| Joint union | |
| Independent intersection | |
| Conditional probability | |
| Bayes' theorem | |
| Binomial distribution | |
| Normal distribution |
Quiz#
Q1. If you flip a fair coin twice, what is the probability of getting exactly one head and one tail (in any order)?
Show answer
Possible outcomes: HH, HT, TH, TT (4 total)
Outcomes with one head and one tail: HT, TH (2 outcomes)
Q2. What is the probability that two dice sum to 10?
Show answer
Total outcomes:
Outcomes that sum to 10: → 3 outcomes
Q3. Can you determine from the following information?
Among 100 patients, 50 experienced a headache and 50 had a fever.
- Cannot be determined
Show answer
Answer 1 — Cannot be determined
We don't know how many patients had both symptoms simultaneously ().
For joint events, knowing the intersection is essential.
Q4. A factory produces product A (70% of output) and product B (30%). The quality inspection pass rate is 80% for A and 90% for B. Given that a product passes inspection, what is the probability it is product A?
Show answer
Applying Bayes' theorem:
Numerator:
Denominator (total probability of passing):
Result:
The probability dropped slightly from the prior of 70% to 67.5%, because product B has a higher pass rate.
Q5. What is the probability of rolling an odd number or a prime number on a single die?
Show answer
- Odd numbers: →
- Prime numbers: →
- Intersection (odd and prime): →
Applying the addition rule for joint events:
The next post will cover expected value and variance, skewness and kurtosis, covariance and correlation, and the multivariate normal distribution.
// Related Posts
Probability & Statistics in Practice: Inference Problems from the ML Trenches
From probability fundamentals and Bayes' theorem to distributions, MLE/MAP, confidence intervals, and hypothesis testing — a collection of practice problems grounded in real ML and data analysis scenarios.
Probability & Statistics Coding Assignments: Building ML Statistical Tools in Python
Bayesian updates, distribution simulation, CLT verification, MLE/MAP implementation, confidence intervals, hypothesis testing, and a full A/B test pipeline — implementing probability & statistics chapters 1–4 in code.
ML Probability & Statistics Chapter 4: Confidence Intervals and Hypothesis Testing
A complete guide to confidence intervals, the t-distribution, hypothesis testing fundamentals (null/alternative hypotheses, p-values, rejection regions, statistical power), various t-tests, and A/B testing.