j-devlog
KO
~/nav

// categories

// tags

[MMD]

ML Probability & Statistics Chapter 1: Foundations of Probability and Probability Distributions

·14 min read·

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.


P(A)=number of outcomes where A occurstotal number of possible outcomesP(A) = \frac{\text{number of outcomes where A occurs}}{\text{total number of possible outcomes}}


Examples

  • 3 out of 10 people play soccer: P(soccer)=310=30%P(\text{soccer}) = \frac{3}{10} = 30\%
  • Rolling a 6 on a six-sided die: P(6)=16P(6) = \frac{1}{6}
  • Getting heads twice in two coin flips: P(HH)=14P(HH) = \frac{1}{4}

Experiment: Any process that produces an uncertain outcome

Sample Space: The set of all possible outcomes


Complement#

The probability that event AA does not occur:


P(Ac)=1P(A)P(A^c) = 1 - P(A)

ExampleCalculation
Probability of not playing soccer1310=7101 - \frac{3}{10} = \frac{7}{10}
Probability of not rolling a 6116=561 - \frac{1}{6} = \frac{5}{6}
Probability of not getting all heads in 3 flips118=781 - \frac{1}{8} = \frac{7}{8}

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.


P(AB)=P(A)+P(B)P(A \cup B) = P(A) + P(B)


Example

  • Probability of rolling an even number or a 5: P(even)=36P(\text{even}) = \frac{3}{6}, P(5)=16P(5) = \frac{1}{6}P(even or 5)=46=23P(\text{even or 5}) = \frac{4}{6} = \frac{2}{3}

Addition Rule — Joint Events#

Joint Events: Events that can overlap. You must subtract the intersection to avoid double-counting.


P(AB)=P(A)+P(B)P(AB)P(A \cup B) = P(A) + P(B) - P(A \cap B)


Example — soccer (0.6), basketball (0.5), both (0.3):


P(soccer or basketball)=0.6+0.50.3=0.8P(\text{soccer or basketball}) = 0.6 + 0.5 - 0.3 = 0.8

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 AA and BB are independent if the occurrence of one has no effect on the probability of the other.


P(AB)=P(A)×P(B)P(A \cap B) = P(A) \times P(B)


Examples

  • Getting heads 5 times in a row: P=(12)5=132P = \left(\frac{1}{2}\right)^5 = \frac{1}{32}
  • Rolling a 6 ten times in a row: P=(16)10P = \left(\frac{1}{6}\right)^{10}

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:


P(at least one shared birthday)=1P(all different birthdays)P(\text{at least one shared birthday}) = 1 - P(\text{all different birthdays})


P(all different)=365365×364365×363365××3363650.294P(\text{all different}) = \frac{365}{365} \times \frac{364}{365} \times \frac{363}{365} \times \cdots \times \frac{336}{365} \approx 0.294


P(at least one shared birthday)10.294=0.706P(\text{at least one shared birthday}) \approx 1 - 0.294 = 0.706

Lesson: Our intuition about probability is often wrong. Always work it out with math.


Conditional Probability#

Concept#

Conditional probability: The probability that event AA occurs, given that event BB has already occurred.


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


Notation: P(AB)P(A \mid B) ("the probability of A given B")

Example — two coin flips:

  • P(HHfirst flip is H)P(HH \mid \text{first flip is H}) = 12\frac{1}{2} (if the first is H, only the second needs to be H)
  • P(HHfirst flip is T)P(HH \mid \text{first flip is T}) = 0 (HH is impossible if the first flip is T)

Product Rule#

The probability of the intersection of two dependent events:


P(AB)=P(A)×P(BA)P(A \cap B) = P(A) \times P(B \mid A)


Example — 40% of students play soccer, and 80% of those wear running shoes:


P(soccerrunning shoes)=0.4×0.8=0.32P(\text{soccer} \cap \text{running shoes}) = 0.4 \times 0.8 = 0.32

Independent vs. dependent: If events are related, they are dependent and conditional probability must be used.


Bayes' Theorem#

Formula#

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

TermMeaning
P(A)P(A)Prior — our baseline belief before seeing any evidence
P(AB)P(A \mid B)Posterior — our updated belief after observing evidence BB
P(BA)P(B \mid A)Likelihood — the probability of observing B given A
P(B)P(B)Evidence — the overall probability of observing B

Spam Email Example#

  • 20% of emails are spam: P(spam)=0.2P(\text{spam}) = 0.2
  • 40% of spam emails contain "lottery": P(lotteryspam)=0.4P(\text{lottery} \mid \text{spam}) = 0.4
  • 10% of all emails contain "lottery": P(lottery)=0.1P(\text{lottery}) = 0.1

P(spamlottery)=0.4×0.20.1=0.8P(\text{spam} \mid \text{lottery}) = \frac{0.4 \times 0.2}{0.1} = 0.8


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:


P(AB1,B2,,Bn)P(A)P(B1A)P(B2A)P(BnA)P(A \mid B_1, B_2, \ldots, B_n) \propto P(A) \cdot P(B_1 \mid A) \cdot P(B_2 \mid A) \cdots P(B_n \mid A)


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.

TypeDescriptionExamples
DiscreteA countable, finite set of valuesNumber of heads in coin flips, die roll result
ContinuousInfinitely many values within an intervalHeight, temperature, waiting time

Discrete Probability Distributions#

Binomial Distribution#

The probability of getting exactly kk successes in nn independent trials, each with success probability pp:


P(X=k)=(nk)pk(1p)nkP(X = k) = \binom{n}{k} p^k (1-p)^{n-k}


Binomial Coefficient:


(nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k!(n-k)!}


The number of ways to choose kk items from nn without regard to order.

Example — the probability of rolling a 1 exactly 3 times in 5 die rolls:


P(X=3)=(53)(16)3(56)2P(X=3) = \binom{5}{3} \left(\frac{1}{6}\right)^3 \left(\frac{5}{6}\right)^2


Properties:

  • p=0.5p = 0.5 → symmetric distribution
  • p0.5p \neq 0.5 → skewed distribution
  • As nn grows large, converges to a normal distribution

Bernoulli Distribution#

A special case of the binomial distribution (n=1n = 1). A single trial with only two outcomes: success or failure.


P(X=k)={pk=1 (success)1pk=0 (failure)P(X = k) = \begin{cases} p & k = 1 \text{ (success)} \\ 1 - p & k = 0 \text{ (failure)} \end{cases}


Example: The probability of rolling a 2 on a 4-sided die → Bernoulli(p=14)\text{Bernoulli}(p = \frac{1}{4})

Bernoulli distribution = Binomial distribution Binomial(1,p)\text{Binomial}(1, p)


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.


P(aXb)=abf(x)dxP(a \leq X \leq b) = \int_a^b f(x) \, dx


f(x)f(x): Probability Density Function

Properties:

  • f(x)0f(x) \geq 0
  • f(x)dx=1\int_{-\infty}^{\infty} f(x) \, dx = 1 (total area = 1)

Discrete: PMF (Probability Mass Function) ↔ Continuous: PDF (Probability Density Function)

Cumulative Distribution Function (CDF)#

F(x)=P(Xx)=xf(t)dtF(x) = P(X \leq x) = \int_{-\infty}^{x} f(t) \, dt


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 [0,1][0,1] distribution and apply the inverse CDF to get a sample from the desired distribution.


Uniform Distribution#

A distribution where every value in the interval [a,b][a, b] has equal probability.


f(x)=1ba,axbf(x) = \frac{1}{b - a}, \quad a \leq x \leq b


Parameters: aa (lower bound), bb (upper bound)

Example: If hold time is uniformly distributed between 0 and 5 minutes → P(2X3)=15=20%P(2 \leq X \leq 3) = \frac{1}{5} = 20\%


Normal (Gaussian) Distribution#

The most widely used distribution in machine learning. It appears frequently in natural phenomena (height, measurement error, etc.).


f(x)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}


Parameters:

  • μ\mu (mu): mean — determines the location of the distribution
  • σ\sigma (sigma): standard deviation — determines the spread of the distribution

Standard Normal Distribution: μ=0\mu = 0, σ=1\sigma = 1ZN(0,1)Z \sim N(0, 1)

Standardization:


Z=XμσZ = \frac{X - \mu}{\sigma}


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 μ±1σ\mu \pm 1\sigma
  • About 95% of data falls within μ±2σ\mu \pm 2\sigma
  • About 99.7% of data falls within μ±3σ\mu \pm 3\sigma

Chi-Squared Distribution#

The distribution of the sum of squares of kk independent standard normal variables ZiZ_i:


χk2=Z12+Z22++Zk2\chi^2_k = Z_1^2 + Z_2^2 + \cdots + Z_k^2


Parameter: kk (degrees of freedom)

Properties:

  • Small kk: concentrated near 0, right-skewed
  • Large kk: 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#

ConceptFormula / Description
Basic probabilityP(A)=favorable outcomestotal outcomesP(A) = \frac{\text{favorable outcomes}}{\text{total outcomes}}
ComplementP(Ac)=1P(A)P(A^c) = 1 - P(A)
Disjoint unionP(AB)=P(A)+P(B)P(A \cup B) = P(A) + P(B)
Joint unionP(AB)=P(A)+P(B)P(AB)P(A \cup B) = P(A) + P(B) - P(A \cap B)
Independent intersectionP(AB)=P(A)P(B)P(A \cap B) = P(A) \cdot P(B)
Conditional probabilityP(AB)=P(AB)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}
Bayes' theoremP(AB)=P(BA)P(A)P(B)P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}
Binomial distributionP(X=k)=(nk)pk(1p)nkP(X=k) = \binom{n}{k}p^k(1-p)^{n-k}
Normal distributionf(x)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}


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)


P=24=12P = \frac{2}{4} = \frac{1}{2}



Q2. What is the probability that two dice sum to 10?

Show answer

Total outcomes: 6×6=366 \times 6 = 36

Outcomes that sum to 10: (4,6),(5,5),(6,4)(4,6), (5,5), (6,4) → 3 outcomes


P=336=112P = \frac{3}{36} = \frac{1}{12}



Q3. Can you determine P(fever or headache)P(\text{fever or headache}) from the following information?

Among 100 patients, 50 experienced a headache and 50 had a fever.

  1. Cannot be determined
  2. P=1.0P = 1.0
  3. P=0.25P = 0.25
Show answer

Answer 1 — Cannot be determined

We don't know how many patients had both symptoms simultaneously (P(AB)P(A \cap B)).


P(AB)=P(A)+P(B)P(AB)=0.5+0.5?P(A \cup B) = P(A) + P(B) - P(A \cap B) = 0.5 + 0.5 - ?


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:


P(Apass)=P(passA)P(A)P(pass)P(A \mid \text{pass}) = \frac{P(\text{pass} \mid A) \cdot P(A)}{P(\text{pass})}


Numerator: P(passA)P(A)=0.8×0.7=0.56P(\text{pass} \mid A) \cdot P(A) = 0.8 \times 0.7 = 0.56


Denominator (total probability of passing): P(pass)=0.8×0.7+0.9×0.3=0.56+0.27=0.83P(\text{pass}) = 0.8 \times 0.7 + 0.9 \times 0.3 = 0.56 + 0.27 = 0.83


Result: P(Apass)=0.560.830.675=67.5%P(A \mid \text{pass}) = \frac{0.56}{0.83} \approx 0.675 = 67.5\%


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: {1,3,5}\{1, 3, 5\}P=36=12P = \frac{3}{6} = \frac{1}{2}
  • Prime numbers: {2,3,5}\{2, 3, 5\}P=36=12P = \frac{3}{6} = \frac{1}{2}
  • Intersection (odd and prime): {3,5}\{3, 5\}P=26=13P = \frac{2}{6} = \frac{1}{3}

Applying the addition rule for joint events:


P(odd or prime)=12+1213=113=23P(\text{odd or prime}) = \frac{1}{2} + \frac{1}{2} - \frac{1}{3} = 1 - \frac{1}{3} = \frac{2}{3}



The next post will cover expected value and variance, skewness and kurtosis, covariance and correlation, and the multivariate normal distribution.

// Related Posts