Skip to main content

Updated Aug 15, 2026

Probability and Distributions

A classifier doesn't output "the answer" — it outputs a belief, expressed as a probability distribution over possible answers. Every loss function in this knowledge base is a statement about how that belief compares to reality. This page is the probability vocabulary everything downstream assumes you already have.

Key idea

A classifier's output is a conditional distribution p(y∣x)p(y \mid x), and every loss here is a statement about that distribution.

A six-panel grid of normal, binomial, Poisson, exponential and beta distributions plus a central limit theorem demonstration
The distributions that recur throughout ML. The last panel is the central limit theorem in action: averages of uniform samples become normal remarkably quickly, which is why the normal assumption is so often defensible.

Sample space, events, random variables​

The sample space Ω\Omega is the set of all possible outcomes (e.g., all six faces of a die). An event is a subset of Ω\Omega (e.g., "rolled an even number"). A random variable XX is a function mapping outcomes to numbers, letting you talk about "the value" rather than "the outcome."

Discrete vs. continuous: PMF, PDF, CDF​

  • PMF (probability mass function), discrete XX: p(x)=P(X=x)p(x) = P(X = x), and ∑xp(x)=1\sum_x p(x) = 1.
  • PDF (probability density function), continuous XX: f(x)f(x) where P(a≤X≤b)=∫abf(x) dxP(a \le X \le b) = \int_a^b f(x)\,dx. Note f(x)f(x) is not a probability itself — only the integral over a range is.
  • CDF (cumulative distribution function): F(x)=P(X≤x)F(x) = P(X \le x), applies to both.

Expectation and variance​

E[X]=∑xx p(x)(discrete),E[X]=∫xf(x) dx(continuous)\mathbb{E}[X] = \sum_x x \, p(x) \quad \text{(discrete)}, \qquad \mathbb{E}[X] = \int x f(x)\,dx \quad \text{(continuous)} Var(X)=E[(X−E[X])2]\text{Var}(X) = \mathbb{E}\big[(X - \mathbb{E}[X])^2\big]
SymbolMeaning
E[X]\mathbb{E}[X]expectation — the long-run average value of XX
Var(X)\text{Var}(X)variance — expected squared deviation from the mean

Joint, marginal, conditional​

  • Joint: p(x,y)p(x, y), the probability of both X=xX=x and Y=yY=y.
  • Marginal: p(x)=∑yp(x,y)p(x) = \sum_y p(x, y) — summing out the variable you don't care about.
  • Conditional: p(y∣x)=p(x,y)p(x)p(y \mid x) = \frac{p(x, y)}{p(x)} — the distribution of YY once XX is known.

Independence​

XX and YY are independent iff p(x,y)=p(x)p(y)p(x, y) = p(x)p(y) for all x,yx, y — equivalently, knowing XX tells you nothing about YY. This assumption is the backbone of Naive Bayes, and it's usually false — which is exactly why that page is interesting.

Bayes' rule​

p(y∣x)=p(x∣y) p(y)p(x)p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)}

Worked example (the base-rate trap): a disease affects 1% of the population; a test is 99% accurate (both sensitivity and specificity). Given a positive test, what's the probability of actually having the disease?

p(disease∣positive)=0.99×0.010.99×0.01+0.01×0.99=0.5p(\text{disease} \mid \text{positive}) = \frac{0.99 \times 0.01}{0.99 \times 0.01 + 0.01 \times 0.99} = 0.5

Only 50%, not 99% — because the disease is rare, false positives from the healthy 99% of the population outnumber true positives from the sick 1%. Ignoring the base rate p(y)p(y) is the single most common probability mistake in applied ML.

The distributions that matter​

DistributionSupportUse
Bernoulli{0,1}\{0, 1\}a single binary outcome (coin flip, binary label)
Categorical{1,…,K}\{1, \ldots, K\}a single outcome among KK classes
Gaussian (Normal)R\mathbb{R}continuous data, noise, weight initialisation
Uniform[a,b][a, b]"no prior preference" over a range
Exponential[0,∞)[0, \infty)waiting times, time-to-event

The Gaussian's special status​

The Gaussian N(μ,σ2)\mathcal{N}(\mu, \sigma^2) has PDF f(x)=1σ2πe−(x−μ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}. It arises constantly because of the central limit theorem: the sum (or mean) of many independent random variables tends toward a Gaussian, regardless of their original distribution — which is why noise, measurement error, and aggregated effects are so often modelled as Gaussian.

Code: sampling, plotting, and an empirical CLT demo​

distributions_demo.py
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)

# --- Sample from each named distribution ---
bernoulli = rng.binomial(1, p=0.3, size=1000)
categorical = rng.choice([0, 1, 2], p=[0.5, 0.3, 0.2], size=1000)
gaussian = rng.normal(loc=0, scale=1, size=1000)
uniform = rng.uniform(low=-1, high=1, size=1000)
exponential = rng.exponential(scale=1.0, size=1000)

print("bernoulli mean:", bernoulli.mean())
print("gaussian mean/std:", gaussian.mean(), gaussian.std())

# --- Empirical central limit theorem ---
n_samples, n_sums = 10000, 30
uniform_sums = rng.uniform(0, 1, size=(n_samples, n_sums)).sum(axis=1)

fig, axes = plt.subplots(1, 2, figsize=(10, 4))
axes[0].hist(rng.uniform(0, 1, n_samples), bins=50)
axes[0].set_title("single uniform draw")
axes[1].hist(uniform_sums, bins=50)
axes[1].set_title(f"sum of {n_sums} uniform draws (bell-shaped)")
plt.savefig("clt_demo.png")

Summing 30 uniform draws already looks visibly bell-shaped despite the uniform distribution having no bell shape at all — the CLT in action.

See also​