Skip to content

Discrete and Continuous Probabilities

Probability comes in two flavors depending on whether outcomes are countable (discrete) or form a continuum (continuous). Discrete variables use a probability mass function; continuous ones use a probability density function and a cumulative distribution function. Getting the difference straight — especially that a density can exceed 1 — is essential for reading any probabilistic ML model.

A real-life example: category vs. measurement

A user’s country is discrete (a finite set of labels) — model it with a probability mass function that assigns a probability to each country. A user’s height is continuous (any real number in a range) — model it with a probability density function, where only intervals (“between 170 and 180 cm”) have nonzero probability. Categorical → mass; measured → density.

Discrete: the probability mass function

For a discrete random variable, the probability mass function (pmf) gives the probability of each value directly:

P(X=x),xP(X=x)=1,0P(X=x)1.P(X = x), \qquad \sum_x P(X = x) = 1, \qquad 0 \le P(X = x) \le 1.

With two variables, the joint pmf p(x,y)=P(X=x,Y=y)p(x, y) = P(X{=}x, Y{=}y) fills a table. Summing across a row or column gives the marginal; restricting to one row/column and renormalizing gives the conditional:

p(x)=yp(x,y)(marginal),p(yx)=p(x,y)p(x)(conditional).p(x) = \sum_y p(x, y) \quad(\text{marginal}), \qquad p(y \mid x) = \frac{p(x, y)}{p(x)} \quad(\text{conditional}).

Continuous: density and cumulative functions

A probability density function (pdf) f(x)f(x) satisfies two rules:

f(x)0for all x,f(x)dx=1.f(x) \ge 0 \quad\text{for all } x, \qquad \int_{-\infty}^{\infty} f(x)\,dx = 1.

Probability comes from integrating the density over an interval: P(aXb)=abf(x)dxP(a \le X \le b) = \int_a^b f(x)\,dx. The cumulative distribution function (cdf) accumulates this from the left:

FX(x)=P(Xx)=xf(t)dt.F_X(x) = P(X \le x) = \int_{-\infty}^{x} f(t)\,dt.

Watch the pdf integrate into the cdf

The top panel is a pdf f(x)f(x); the shaded area to the left of the sweeping line is P(Xx)P(X \le x). The bottom panel plots that accumulated area — the cdf — climbing from 0 to 1 as the line sweeps right:

sketch From pdf to cdf: accumulating area p5.js
Top: a probability density f(x) with the area left of the moving line shaded (= P(X ≤ x)). Bottom: that area plotted as the cumulative distribution function, rising from 0 to 1.

The cdf is just “how much probability have we accumulated so far” — it always starts at 0, ends at 1, and never decreases.

Discrete vs. continuous, side by side

diagram Diagram mermaid

NumPy

pmf_pdf_cdf.py
import numpy as np
 
# Discrete: pmf of a fair die — each face 1/6, sums to 1
pmf = np.full(6, 1/6)
print("pmf sums to 1:", np.isclose(pmf.sum(), 1.0))
 
# Continuous uniform on [0.9, 1.6]: density height > 1
a, b = 0.9, 1.6
height = 1 / (b - a)
print(f"uniform density height = {height:.3f} (> 1, but area = {(b-a)*height:.1f})")
 
# pdf -> cdf by cumulative integration (trapezoid) for a standard normal
x = np.linspace(-4, 4, 2001)
pdf = np.exp(-0.5 * x**2) / np.sqrt(2 * np.pi)
cdf = np.cumsum(pdf) * (x[1] - x[0])
print("cdf at x=0  ≈", round(cdf[np.argmin(abs(x))], 3))   # ~0.5
print("cdf at x=4  ≈", round(cdf[-1], 3))                   # ~1.0
pmf_pdf_cdf.py
import numpy as np
 
# Discrete: pmf of a fair die — each face 1/6, sums to 1
pmf = np.full(6, 1/6)
print("pmf sums to 1:", np.isclose(pmf.sum(), 1.0))
 
# Continuous uniform on [0.9, 1.6]: density height > 1
a, b = 0.9, 1.6
height = 1 / (b - a)
print(f"uniform density height = {height:.3f} (> 1, but area = {(b-a)*height:.1f})")
 
# pdf -> cdf by cumulative integration (trapezoid) for a standard normal
x = np.linspace(-4, 4, 2001)
pdf = np.exp(-0.5 * x**2) / np.sqrt(2 * np.pi)
cdf = np.cumsum(pdf) * (x[1] - x[0])
print("cdf at x=0  ≈", round(cdf[np.argmin(abs(x))], 3))   # ~0.5
print("cdf at x=4  ≈", round(cdf[-1], 3))                   # ~1.0
text
pmf sums to 1: True
uniform density height = 1.429 (> 1, but area = 1.0)
cdf at x=00.5
cdf at x=41.0
text
pmf sums to 1: True
uniform density height = 1.429 (> 1, but area = 1.0)
cdf at x=00.5
cdf at x=41.0

Why this matters for ML

  • Discrete distributions model categorical features and class labels (softmax outputs are a pmf over classes).
  • Continuous densities model measurements, weights, and noise; likelihoods are products of densities.
  • Joint / marginal / conditional structure is the vocabulary of graphical models, and the reason “marginalize out the nuisance variable” is a core ML operation.

🧪 Try It Yourself

Exercise 1 – A valid pmf

Exercise 2 – Marginal from a joint table

Exercise 3 – Density can exceed 1

Recap

  • Discrete variables use a pmf (P(X=x)P(X{=}x), sums to 1); continuous ones use a pdf (f(x)0f(x) \ge 0, integrates to 1) and a cdf (F(x)=P(Xx)F(x) = P(X \le x)).
  • A density is not a probability — it can exceed 1; only the area (an interval’s integral) is a probability.
  • Joint → marginal (sum/integrate out) → conditional (restrict and renormalize) is the core toolkit.

Next: the two rules that generate all of probability — sum, product, and Bayes.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did