Skip to content
BIASED

Continuous distributions

Density and the probability of an interval as an area, why a density can exceed one, the CDF and quantiles; the uniform, exponential (memoryless) and normal distributions, and gamma and beta in brief.

From sums to areas

The topic Discrete distributions described a random variable by its pmf: list the values, give each one a probability, add them up. That works for counts. But a server's response time, a person's height or a classifier's score take values on a continuum, and there the list breaks down.

The reason already appeared in the topic Kolmogorov's axioms: for a point uniform on [0,1][0, 1], every single value has probability 00. Adding up zeros gives nothing. So we stop asking about points and start asking about intervals.

A density is a function pX(x)≥0p_X(x) \ge 0 whose graph encloses total area 11. The probability that XX lands in an interval is the area under the density over that interval:

P(a≤X≤b)=∫abpX(x) dx.P(a \le X \le b) = \int_a^b p_X(x)\,dx.

That is all we need from integrals in this topic: ∫ab\int_a^b is the area under the graph between aa and bb. A random variable with a density is called continuous.

Two consequences follow at once. First, P(X=a)=0P(X = a) = 0 for every aa, because a vertical line has no area. Second, endpoints do not matter: P(a≤X≤b)=P(a<X<b)P(a \le X \le b) = P(a < X < b).

An example we will reuse: the density p(x)=2xp(x) = 2x on [0,1][0, 1], and 00 elsewhere. Its graph is a triangle with base 11 and height 22, so the area is 11. The probability P(X≤0.5)P(X \le 0.5) is the small triangle with base 0.50.5 and height 11:

P(X≤0.5)=12⋅0.5⋅1=0.25.P(X \le 0.5) = \tfrac12 \cdot 0.5 \cdot 1 = 0.25.

Values near 11 are more likely than values near 00, even though each single value has probability zero.

A density is not a probability

The height pX(x)p_X(x) is not a probability. Over a short interval of width hh the density is almost flat, so the area is close to a rectangle:

P(x≤X≤x+h)≈pX(x) h.P(x \le X \le x + h) \approx p_X(x)\, h.

A density is probability per unit length. Nothing stops it from exceeding 11. A point uniform on [0,0.5][0, 0.5] has density 22 there: the area must be 11 over a length of 0.50.5. The narrower the range, the taller the density.

Units change density values but not probabilities. Let a height be uniform between 160160 and 200200 cm. The density is 1/40=0.0251/40 = 0.025 per centimetre. In metres the same range has length 0.40.4, and the density becomes 2.52.5 per metre, 100100 times larger. The probability of being taller than 1.91.9 m is 0.250.25 either way.

So a single density value means little on its own. Densities are compared with each other ("values near xx are twice as likely as values near yy") or turned into probabilities through areas. This matters in ML: a model that reports a positive log-density for a data point is not broken. The density there is simply above 11.

The CDF and quantiles

The topic Discrete distributions introduced the CDF FX(x)=P(X≤x)F_X(x) = P(X \le x). The definition stays the same. For a continuous variable it is the area to the left of xx:

FX(x)=∫−∞xpX(t) dt.F_X(x) = \int_{-\infty}^{x} p_X(t)\,dt.

It climbs from 00 to 11 and never goes down. For a discrete variable it was a staircase with jumps at the values. A continuous variable has no single values with positive probability, so its CDF has no jumps. Any interval probability is a difference of two CDF values:

P(a<X≤b)=FX(b)−FX(a).P(a < X \le b) = F_X(b) - F_X(a).

In the other direction, the density is the slope of the CDF: pX(x)=FX′(x)p_X(x) = F_X'(x) wherever pXp_X is continuous. (A derivative is the slope of a graph; Mathematics for ML has more.) Where the CDF is steep, probability is dense; where it is flat, there is none. For the triangle density p(x)=2xp(x) = 2x the CDF is F(x)=x2F(x) = x^2 on [0,1][0, 1], and its slope is 2x2x again.

Reading the CDF backwards gives quantiles. The qq-quantile is the point xqx_q with

FX(xq)=q,F_X(x_q) = q,

so a fraction qq of the probability lies to its left. If FXF_X is flat on a stretch and the equation has many solutions, take the leftmost one. The median is the 0.50.5-quantile; the quartiles are the 0.250.25- and 0.750.75-quantiles. When a service promises "p99 latency of 300 ms", it says that the 0.990.99-quantile of the response time is 300300 ms: only one request in a hundred is slower.

For the triangle, x2=0.5x^2 = 0.5 gives the median 0.5≈0.71\sqrt{0.5} \approx 0.71. Half of the probability sits between 0.710.71 and 11, where the density is tall.

Uniform and exponential

Now the named families. The simplest is the uniform distribution U(a,b)U(a, b), with a constant density on [a,b][a, b]:

p(x)=1b−a,a≤x≤b.p(x) = \frac{1}{b - a}, \qquad a \le x \le b.

The probability of a sub-interval is its length divided by b−ab - a. U(0,1)U(0, 1) is where simulation starts: np.random.rand() returns (approximately) a draw from it, and every other sampler in this course is built from such draws.

The exponential distribution is the continuous version of the geometric one. Requests reach a server at rate λ\lambda per second, and we wait for the first one. Split time into short slots of length Δ\Delta. Each slot, independently, holds a request with probability λΔ\lambda\Delta. Waiting longer than tt means that the first t/Δt/\Delta slots are all empty — a geometric count of trials:

P(T>t)=(1−λΔ)t/Δ  ⟶  e−λt(Δ→0).P(T > t) = (1 - \lambda\Delta)^{t/\Delta} \;\longrightarrow\; e^{-\lambda t} \qquad (\Delta \to 0).

At λ=1\lambda = 1 and t=1t = 1, slots of 0.50.5 give 0.250.25, slots of 0.10.1 give 0.3490.349, and the limit is e−1≈0.368e^{-1} \approx 0.368. So T∼Exp⁡(λ)T \sim \operatorname{Exp}(\lambda) has CDF and density

F(t)=1−e−λt,p(t)=λe−λt,t≥0.F(t) = 1 - e^{-\lambda t}, \qquad p(t) = \lambda e^{-\lambda t}, \qquad t \ge 0.

The Poisson distribution gives the same answer from the other side. If the number of requests in tt seconds is Pois⁡(λt)\operatorname{Pois}(\lambda t), then T>tT > t means zero requests, and that has probability e−λte^{-\lambda t}. At 22 requests per second, a whole second without a request has probability e−2≈0.135e^{-2} \approx 0.135.

The density is highest at 00 and decays. Short waits are common; long ones are rare but do happen. At λ=2\lambda = 2, half of all waits are shorter than 0.350.35 s, yet a wait longer than 22 s still has probability e−4≈0.018e^{-4} \approx 0.018.

Memorylessness

Suppose 22 seconds have passed without a request. How long is the rest of the wait? Conditional probability from the topic Conditional probability and Bayes' formula answers this. The event {T>s+t}\{T > s + t\} lies inside {T>s}\{T > s\}, so

P(T>s+t∣T>s)=P(T>s+t)P(T>s)=e−λ(s+t)e−λs=e−λt=P(T>t).P(T > s + t \mid T > s) = \frac{P(T > s + t)}{P(T > s)} = \frac{e^{-\lambda(s + t)}}{e^{-\lambda s}} = e^{-\lambda t} = P(T > t).

The time already spent is forgotten: the exponential distribution is memoryless. At every moment the clock starts afresh. It inherits this from the geometric distribution, which forgets failed trials in the same way. Among continuous distributions, the exponential is the only memoryless one.

This is a strong modelling assumption, and it is often false:

  • Arrivals from many independent sources — requests to a large service, radioactive decays — are close to memoryless.
  • Things that wear out are not. A disk that has run for five years is closer to failure than a new one.
  • A fixed schedule is not either. A bus every 1010 minutes has rate 1/101/10 per minute. But if you arrive at a random moment, your wait is uniform on [0,10][0, 10] and never exceeds 1010 minutes. After 99 minutes at the stop, the bus is at most 11 minute away: this clock clearly remembers.

The same rate can come with different distributions. A rate alone does not make a waiting time exponential.

The normal distribution

The normal, or Gaussian, distribution N(μ,σ2)\mathcal N(\mu, \sigma^2) has a bell-shaped density:

p(x)=1σ2π exp⁡ ⁣(−(x−μ)22σ2).p(x) = \frac{1}{\sigma\sqrt{2\pi}}\, \exp\!\Big(-\frac{(x - \mu)^2}{2\sigma^2}\Big).

The parameter μ\mu is the centre, where the bell peaks, and σ>0\sigma > 0 is its width. The topic Expectation and variance will show that μ\mu is the mean and σ2\sigma^2 the variance. The second argument of N\mathcal N is always σ2\sigma^2: N(0,4)\mathcal N(0, 4) has width σ=2\sigma = 2. The case N(0,1)\mathcal N(0, 1) is the standard normal distribution, and its CDF is written Φ\Phi.

Every normal is a shifted and stretched standard one: if X∼N(μ,σ2)X \sim \mathcal N(\mu, \sigma^2), then Z=(X−μ)/σ∼N(0,1)Z = (X - \mu)/\sigma \sim \mathcal N(0, 1). The next topic proves it. For now it means one function serves all normals:

P(X≤x)=Φ(x−μσ).P(X \le x) = \Phi\Big(\frac{x - \mu}{\sigma}\Big).

Φ\Phi has no formula in elementary functions; libraries compute it numerically (scipy.stats.norm.cdf). Three numbers are worth remembering. A normal variable lies within 11, 22 and 33 widths σ\sigma of μ\mu with probabilities 0.6830.683, 0.9540.954 and 0.9970.997. This is the 68–95–99.7 rule.

The tails are thin. P(Z>3)≈0.00135P(Z > 3) \approx 0.00135 and P(Z>5)≈3⋅10−7P(Z > 5) \approx 3 \cdot 10^{-7}: far from the centre the density falls like e−x2/2e^{-x^2/2}, much faster than the exponential e−λxe^{-\lambda x}. Say a regression model's errors follow N(0,0.22)\mathcal N(0, 0.2^2) and we flag errors larger than 0.50.5 in absolute value. That is 2.5σ2.5\sigma on each side, and 2 Φ(−2.5)≈0.01242\,\Phi(-2.5) \approx 0.0124 of predictions get flagged.

The normal shows up wherever many small independent effects add up: measurement noise, averages over a dataset. The topic The central limit theorem explains why. Where extremes matter — financial returns, request latencies — a normal model underestimates them.

Gamma and beta

Two more families, briefly. The topic Bayesian inference will use both.

Gamma. The exponential distribution waits for the first request; the gamma distribution waits for the aa-th. With rate bb, its density on x>0x > 0 is

p(x)=baΓ(a) xa−1e−bx.p(x) = \frac{b^a}{\Gamma(a)}\, x^{a - 1} e^{-bx}.

The gamma function extends the factorial: Γ(n)=(n−1)!\Gamma(n) = (n - 1)! for whole nn, and Γ(a)\Gamma(a) exists for every a>0a > 0, so non-integer shapes are allowed too. With a=1a = 1 the formula becomes be−bxb e^{-bx}, so Gamma⁡(1,b)=Exp⁡(b)\operatorname{Gamma}(1, b) = \operatorname{Exp}(b). For a>1a > 1 the density starts at 00 and peaks at x=(a−1)/bx = (a - 1)/b. At 22 requests per second, the third request takes longer than 11 second with probability 0.6770.677: that is the chance of fewer than 33 requests in the first second, a Poisson sum. One trap: scipy.stats.gamma takes the scale 1/b1/b, not the rate bb.

Beta. A conversion rate, a coin's bias, a click probability all live in [0,1][0, 1]. The beta distribution is the standard model for such a number:

p(x)=xa−1(1−x)b−1B(a,b),0≤x≤1.p(x) = \frac{x^{a - 1}(1 - x)^{b - 1}}{B(a, b)}, \qquad 0 \le x \le 1.

The constant B(a,b)B(a, b) makes the area equal to 11. Beta⁡(1,1)\operatorname{Beta}(1, 1) is U(0,1)U(0, 1). A larger aa pushes the mass toward 11, a larger bb toward 00, and a=ba = b gives a shape symmetric around 0.50.5. For a,b>1a, b > 1 the peak is at

x∗=a−1a+b−2.x^* = \frac{a - 1}{a + b - 2}.

Beta⁡(2,5)\operatorname{Beta}(2, 5) peaks at 0.20.2 with height about 2.462.46 — one more density above one. In the topic Bayesian inference a beta distribution will describe what we believe about an unknown conversion rate, and the data will update aa and bb.

Discrete and continuous side by side

The two kinds of random variables side by side:

Discrete Continuous
Described by pmf pX(x)=P(X=x)p_X(x) = P(X = x) density pX(x)p_X(x)
P(X=x)P(X = x) can be positive always 00
P(a≤X≤b)P(a \le X \le b) sum of the pmf area under the density
CDF staircase climbs without jumps
Memoryless waiting time geometric exponential

Not everything fits one column. Revenue per visitor in an A/B test is exactly 00 for most visitors and a spread-out amount for the rest. That is a mixed distribution: an atom at 00 plus a density over positive amounts. Its CDF jumps at 00 and then climbs smoothly. And a named family is a model, not a fact: its fit to the data has to be checked.

Models rarely use a variable as it comes. We take the log of a latency, square an error, pass a score through a sigmoid. If XX has a known density, what is the density of Y=g(X)Y = g(X)? We have already seen a hint. Switching from centimetres to metres is Y=X/100Y = X/100, and the density grew 100100 times while every probability stayed put. The next topic, Functions of random variables, turns this into a general rule — and uses it to turn draws from U(0,1)U(0, 1) into samples from any distribution.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.