Continuous Probability Distributions

Uniform, normal and exponential: what changes when the outcome is a measurement instead of a count, how to tell whether your data really is normal, and why averages end up bell-shaped.

Uniform flat: every value equally likely Normal a symmetric bell around the mean Exponential the wait until the next event Uniform flat: every value equally likely Normal a symmetric bell around the mean Exponential the wait until the next event
The three distributions in this article. Each is a density curve, and probabilities are areas underneath it.

Day 9's four distributions were all about counting: how many successes, how many trials, how many events. Plenty of real quantities aren't counts. A delivery doesn't take a whole number of minutes, a server's response time isn't an integer, and a person's height isn't a count of anything. These are measurements, and they can take any value in a range. Today's distributions are built for them.

Three problems to keep in mind:

  1. A train comes every 10 minutes and you turn up at a random moment. How long will you wait?
  2. A shop's orders average $85. How often is an order above $120?
  3. Support tickets arrive at 6 per hour. How long until the next one?

From counting to measuring: a quick recap

Day 8 introduced the key idea, so here's the short version. For a continuous random variable:

Each distribution below is just a different answer to the question "what does f(x) look like?"

1. The uniform distribution

Every value in a range is equally likely. The uniform distribution is a flat line: the same density everywhere between a lower bound a and an upper bound b, and zero outside. It's the natural model when you have no reason to favour any value in a range over another.

f(x) = 1b − a   for a ≤ x ≤ b
E[X] = (a + b)/2 and Var(X) = (b − a)2/12. The height 1/(b − a) is exactly what makes the total area equal 1.

Worked example: waiting for a train

Trains come every 10 minutes and you arrive at a random moment, so your wait is equally likely to be anything from 0 to 10 minutes: X ~ Uniform(0, 10).

Pythonfrom scipy import stats wait = stats.uniform(loc=0, scale=10) # SciPy's uniform runs from loc to loc + scale print(f"Mean wait: {wait.mean():.1f} minutes") print(f"Variance: {wait.var():.2f}") print(f"P(wait < 3): {wait.cdf(3):.2f}") print(f"P(wait > 7): {wait.sf(7):.2f}")
OutputMean wait: 5.0 minutes Variance: 8.33 P(wait < 3): 0.30 P(wait > 7): 0.30
0 2 4 6 8 10 under 3: 30% over 7: 30% density = 1/10 everywhere from 0 to 10 wait in minutes 0 2 4 6 8 10 under 3: 30% over 7: 30% density = 1/10 everywhere from 0 to 10 wait in minutes
With a flat density, probability is just a share of the range: 3 minutes out of 10 is 30%, at either end.
SciPy gotcha: loc and scale

SciPy describes the uniform distribution by where it starts (loc) and how wide it is (scale), not by its two endpoints. Uniform(2, 5) is stats.uniform(loc=2, scale=3). Writing scale=5 by mistake gives you Uniform(2, 7) with no error message.

Two more places the uniform turns up:

2. The normal distribution

The bell curve. Many measurements cluster around a central value and thin out symmetrically on both sides: adult heights, measurement errors, many biological traits. That shape is the normal distribution, also called the Gaussian after the mathematician Carl Friedrich Gauss. It's described by just two numbers: the mean μ, which sets the centre, and the standard deviation σ, which sets the spread.

f(x) = 1σ√(2π) · e−(x − μ)2 / (2σ2)
E[X] = μ and Var(X) = σ2. In theory a normal variable can take any value, positive or negative, though values far from μ are vanishingly rare.

z-scores: one scale for every normal distribution

Every normal distribution has its own mean and spread, but they all share one shape. To compare across them, convert a value into a z-score: how many standard deviations it sits from the mean.

z = x − μσ

A z-score of 2 means "two standard deviations above average", whether you're measuring order values in dollars or bolts in millimetres. Converting to z-scores is called standardisation, and it's the same step machine learning libraries apply to features before training many models.

Real case: IQ scores are built to be normal

IQ tests are scored so that the population has a mean of 100 and a standard deviation of about 15, with scores following a bell curve. That makes every score a z-score in disguise: an IQ of 130 is z = (130 − 100)/15 = 2. Under a normal model, about 2.3% of people score above 2 standard deviations, which is why textbooks say "about 2% score above 130", and the same share below 70.

The 68-95-99.7 rule

For every normal distribution, the share of values within a given number of standard deviations of the mean is the same:

−3σ −2σ −1σ μ +1σ +2σ +3σ 68.3% within 1σ: 68.3% within 2σ: 95.4% within 3σ: 99.7% −3σ −2σ −1σ μ +1σ +2σ +3σ 68.3% within 1σ: 68.3% 2σ: 95.4% 3σ: 99.7%
The same split holds for every normal distribution: about 68% within 1 standard deviation, 95% within 2, and 99.7% within 3.

This is why a value more than 3 standard deviations from the mean counts as genuinely unusual for normal data: only about 3 in 1,000 values land out there. (As Day 4 warned, an outlier can inflate the SD itself, so use this rule with care on messy data.)

Worked example: order values

Suppose a shop's order values are roughly normal with a mean of $85 and a standard deviation of $20: X ~ Normal(85, 20). (Real order values are often right-skewed, like Day 3's case study, so always check the shape first. More on that below.)

Pythonorders = stats.norm(loc=85, scale=20) # loc = mean, scale = standard deviation print(f"P(order > $120): {orders.sf(120):.4f}") print(f"P($60 < order < $100): {orders.cdf(100) - orders.cdf(60):.4f}") print(f"Middle 50% of orders: ${orders.ppf(0.25):.2f} to ${orders.ppf(0.75):.2f}") print(f"Top-10% threshold: ${orders.ppf(0.90):.2f}")
OutputP(order > $120): 0.0401 P($60 < order < $100): 0.6677 Middle 50% of orders: $71.51 to $98.49 Top-10% threshold: $110.63
$25 $45 $65 $85 $105 $125 $145 $60 to $100: 66.8% over $120: 4.0% order value $25 $45 $65 $85 $105 $125 $145 $60 to $100: 66.8% over $120: 4.0% order value
A $120 order sits 1.75 standard deviations above the mean, out in the tail. About two-thirds of orders fall between $60 and $100.

A $120 order is z = (120 − 85)/20 = 1.75, and only 4% of orders are that large. The last two lines run the CDF backwards with ppf, Day 8's inverse CDF: half of all orders fall between $71.51 and $98.49, and an order of $110.63 or more puts a customer in the top 10%. Grading curves, "top X%" cut-offs and percentile thresholds all work this way.

Manufacturing tolerances and "Six Sigma"

A factory machines bolts to a target diameter of 10 mm with a standard deviation of 0.05 mm, and anything from 9.85 to 10.15 mm passes inspection. Those limits are exactly 3 standard deviations either side of the target, so by the 68-95-99.7 rule about 99.73% of bolts pass, and about 2,700 in every million fail through ordinary variation alone, with nothing wrong with the machine.

Real case: Motorola's 3.4 defects per million

In 1986 the engineer Bill Smith at Motorola introduced Six Sigma, a quality programme whose name refers to keeping the nearest specification limit six standard deviations from the process average. Its famous target is 3.4 defects per million opportunities. That number doesn't come from six standard deviations, though: the method assumes a process drifts by about 1.5 standard deviations over the long run, leaving a 4.5 standard deviation margin on one side, and the normal tail beyond 4.5σ is 3.4 per million.

Pythonprint(f"Outside ±3 SD, per million: {2 * stats.norm.sf(3) * 1e6:,.0f}") print(f"Beyond 4.5 SD (one side): {stats.norm.sf(4.5) * 1e6:.1f} per million")
OutputOutside ±3 SD, per million: 2,700 Beyond 4.5 SD (one side): 3.4 per million

Is my data actually normal?

A normal model is only as good as the fit. Let's compare two real datasets from earlier in the series: bill lengths of the 151 Adelie penguins in the Palmer penguins data (Day 6), and the 244 restaurant bills from the tips data (Day 8).

Pythonimport numpy as np import seaborn as sns penguins = sns.load_dataset("penguins") adelie = penguins.loc[penguins["species"] == "Adelie", "bill_length_mm"].dropna() bills = sns.load_dataset("tips")["total_bill"] for name, x in [("Adelie bill length", adelie), ("Restaurant bills", bills)]: z = (x - x.mean()) / x.std() shares = [(z.abs() <= k).mean() for k in (1, 2, 3)] print(f"{name:19} within 1/2/3 SD: {shares[0]:.0%} / {shares[1]:.0%} / {shares[2]:.0%} " f"skewness {stats.skew(x):.2f} above +2 SD: {(z > 2).sum()}, below -2 SD: {(z < -2).sum()}")
OutputAdelie bill length within 1/2/3 SD: 68% / 97% / 100% skewness 0.16 above +2 SD: 3, below -2 SD: 2 Restaurant bills within 1/2/3 SD: 72% / 94% / 98% skewness 1.13 above +2 SD: 14, below -2 SD: 0
Adelie penguin bill length (mm) close to a bell 35 40 45 Restaurant bills ($) skewed: a long right tail 0 10 20 30 40 50 Adelie penguin bill length (mm) close to a bell 35 40 45 Restaurant bills ($) skewed: a long right tail 0 10 20 30 40 50
Histograms with a fitted normal curve on top. The penguin data follows the bell. The restaurant bills don't: they bunch up on the left and stretch out to the right, and the normal curve even assigns some probability to bills below $0.

The penguins land close to 68 / 95 / 99.7, with skewness near 0. The restaurant bills are trickier: their percentages (72 / 94 / 98) look almost normal, but every one of the 14 bills more than 2 SDs from the mean is on the high side, and none on the low side. That lopsidedness, skewness 1.13, is exactly what a normal model can't capture. Two lessons: always look at a histogram, not just a few summary numbers; and for skewed, positive data like money or time, a normal model can badly misjudge the tails.

3. The exponential distribution

How long until the next event? When events happen independently at a steady average rate λ (the setting of Day 9's Poisson distribution), the waiting time between one event and the next follows an exponential distribution. It's the continuous version of Day 9's geometric distribution: a wait measured on a clock instead of counted in trials.

f(x) = λ e−λx   for x ≥ 0
E[X] = 1/λ and Var(X) = 1/λ2. The CDF has a simple closed form: P(X ≤ x) = 1 − e−λx.

Worked example: support ticket arrivals

Tickets arrive at 6 per hour, so the average gap is 1/6 of an hour, or 10 minutes.

Pythongap = stats.expon(scale=10) # SciPy wants scale = 1 / rate = mean gap (10 minutes) print(f"Mean gap: {gap.mean():.0f} minutes") print(f"P(next ticket within 5 min): {gap.cdf(5):.4f}") print(f"P(gap longer than 15 min): {gap.sf(15):.4f}") print(f"Median gap: {gap.median():.1f} minutes")
OutputMean gap: 10 minutes P(next ticket within 5 min): 0.3935 P(gap longer than 15 min): 0.2231 Median gap: 6.9 minutes
0 5 10 15 20 25 30 35 40 45 within 5 min: 39.3% over 15 min: 22.3% minutes until the next ticket (mean 10) 0 5 10 15 20 25 30 35 40 45 within 5 min: 39.3% over 15 min: 22.3% minutes until the next ticket (mean 10)
Gaps between tickets arriving at 6 per hour. The curve is tallest at zero: short gaps are the most common, and long ones get steadily rarer.
SciPy gotcha: rate versus scale

Textbooks write the exponential with a rate λ (6 per hour). SciPy's stats.expon takes scale = 1/λ, the mean wait. Writing stats.expon(scale=6) for "6 per hour" silently gives you a mean gap of 6 hours instead of 10 minutes.

Notice the median gap (6.9 minutes) is shorter than the mean (10 minutes). The exponential is right-skewed: most gaps are short, and a few long ones pull the mean up, the same pattern as Day 3's skewed data.

Memoryless, again

The exponential shares the geometric distribution's memoryless property from Day 9. If you've already waited 10 minutes for a ticket, the remaining wait has exactly the same distribution as when you started. For a component that fails at random, a part that has run for 3 years is, under this model, exactly as likely to last 4 more years as a brand-new one.

Take a component with a mean lifetime of 2.5 years (λ = 0.4 per year). P(lasts more than 4 years) = e−1.6 ≈ 20.2%. For a 3-year-old component, P(lasts to year 7 | made it to year 3) = e−2.8 / e−1.2 = e−1.6, the same 20.2%. The 3 years already served simply drop out.

That's a strong assumption. Parts that wear out get more likely to fail as they age, and for them engineers typically use other models, such as the Weibull distribution, that let the failure risk change with age. Use the exponential when events really do happen "at random", with no build-up or wear.

Real case: carbon-14 and the half-life

Radioactive decay is the textbook example of a memoryless process. Each carbon-14 atom has a constant chance of decaying in any given year, regardless of how old it is, so the time until a particular atom decays follows an exponential distribution. The half-life of carbon-14 is 5,730 years: after that long, half the atoms in a sample remain. In distribution terms, the half-life is simply the median of the exponential, ln(2)/λ. After two half-lives a quarter remain, after three an eighth. This is the clock behind radiocarbon dating.

Pythonhalf_life = 5730 rate = np.log(2) / half_life # decay rate per year atom = stats.expon(scale=1 / rate) # lifetime of one carbon-14 atom print(f"Median lifetime (the half-life): {atom.median():,.0f} years") print(f"Mean lifetime: {atom.mean():,.0f} years") print(f"Share left after 10,000 years: {atom.sf(10_000):.1%}")
OutputMedian lifetime (the half-life): 5,730 years Mean lifetime: 8,267 years Share left after 10,000 years: 29.8%
5,730 years: 0.5 11,460 years: 0.25 17,190 years: 0.125 0 0.25 0.5 0.75 1 0 10,000 20,000 30,000 years share of carbon-14 atoms remaining 5,730: 0.5 11,460: 0.25 17,190: 0.125 0 0.25 0.5 0.75 1 0 10,000 20,000 years share of carbon-14 atoms remaining
The share of carbon-14 atoms remaining over time is the exponential's survival function, P(X > t). It halves every 5,730 years.

Choosing the right distribution

DistributionUse it whenParametersE[X]Var(X)In SciPy
Uniform(a, b)Every value in a range is equally likelya, b(a + b)/2(b − a)2/12uniform(loc=a, scale=b-a)
Normal(μ, σ)Values cluster symmetrically around a centreμ, σμσ2norm(loc=mu, scale=sigma)
Exponential(λ)Waiting time until the next random eventλ1/λ1/λ2expon(scale=1/lam)

One process, two distributions

The Poisson and exponential distributions aren't two separate ideas. They're two views of the same random process. Count the events in a fixed window and you get a Poisson distribution. Time the gaps between events and you get an exponential distribution. That's why the Poisson rate λ and the exponential mean 1/λ are reciprocals: 6 tickets per hour means an average gap of 1/6 of an hour.

2 events 3 events 0 events 2 events 0 min 15 min 30 min 45 min 60 min Count events per 15-minute window: Poisson Time the gaps between events: Exponential 2 events 3 events 0 events 2 events 0 min 15 min 30 min 45 min 60 min Count events per 15-minute window: Poisson Time the gaps between events: Exponential
One hour of random events at an average of one per 10 minutes. Counting them per window gives Poisson counts; measuring the gaps gives exponential waiting times.

A first look at the central limit theorem

Here's a claim that sounds too good to be true. Take almost any distribution, even a lopsided one like the exponential. Draw a sample, compute its average, and repeat many times. The averages will form an approximately normal distribution, whatever shape you started with, as long as the samples are big enough.

That's the central limit theorem (CLT), and it's the main reason the normal distribution shows up everywhere. A metric doesn't need to be normal itself for its average to behave like one, and averages are what most statistical methods work with. Two conditions matter: the values should be independent draws, and the original distribution should have a finite variance (a few extremely heavy-tailed distributions break the rule).

Averaging dice

Start with the flattest distribution possible: one fair die, where each face from 1 to 6 is equally likely. Now average 2 dice, then 5, then 30.

Pythonrng = np.random.default_rng(7) for n in [1, 2, 5, 30]: averages = rng.integers(1, 7, size=(100_000, n)).mean(axis=1) # 100,000 rounds of n dice print(f"n = {n:2}: mean {averages.mean():.2f}, SD {averages.std():.3f}, " f"excess kurtosis {stats.kurtosis(averages):+.2f}")
Outputn = 1: mean 3.51, SD 1.710, excess kurtosis -1.27 n = 2: mean 3.50, SD 1.206, excess kurtosis -0.63 n = 5: mean 3.50, SD 0.761, excess kurtosis -0.27 n = 30: mean 3.50, SD 0.312, excess kurtosis -0.06
1 3.5 6 average of 1 die SD 1.71 1 3.5 6 average of 2 dice SD 1.21 1 3.5 6 average of 5 dice SD 0.76 1 3.5 6 average of 30 dice SD 0.31 1 3.5 6 average of 1 die SD 1.71 1 3.5 6 average of 2 dice SD 1.21 1 3.5 6 average of 5 dice SD 0.76 1 3.5 6 average of 30 dice SD 0.31
100,000 rounds of dice, averaged in groups of 1, 2, 5 and 30. A single die is flat; by 30 dice the averages form a narrow bell around 3.5.

The mean stays at 3.5 throughout. What changes is the shape and the spread. "Excess kurtosis" measures how far a distribution's shape is from a normal one in its peak and tails (a normal distribution scores 0). A single die scores about −1.27, very flat. Averages of 30 dice score about −0.06, almost exactly normal. The spread also shrinks, by a factor of √n: the SD of one die is 1.71, and of an average of 30 dice, 1.71/√30 ≈ 0.31.

A harder test: a badly skewed start

Pythonrng = np.random.default_rng(42) samples = rng.exponential(scale=8, size=(100_000, 40)) # 100,000 samples of 40 values each sample_means = samples.mean(axis=1) print(f"Skewness of individual values: {stats.skew(samples.ravel()):.2f}") print(f"Skewness of averages of 40: {stats.skew(sample_means):.2f}") print(f"SD of the averages: {sample_means.std():.3f} (theory: 8 / sqrt(40) = {8 / np.sqrt(40):.3f})")
OutputSkewness of individual values: 2.00 Skewness of averages of 40: 0.31 SD of the averages: 1.261 (theory: 8 / sqrt(40) = 1.265)
0 16 32 48 Individual values Exponential, mean 8, skewness 2.0 4 6 8 10 12 Averages of 40 values skewness 0.31, close to a bell 0 16 32 48 Individual values Exponential, mean 8, skewness 2.0 4 6 8 10 12 Averages of 40 values skewness 0.31, close to a bell
Left: individual values from a heavily skewed exponential distribution. Right: averages of 40 such values, already close to a symmetric bell.

Averaging 40 values cut the skewness from 2.0 to about 0.3, and the spread of the averages matches the σ/√n prediction almost exactly. That quantity, the standard error, is the foundation of Day 11. A common rule of thumb says samples of 30 or more are usually enough for the CLT to kick in, but heavily skewed data, like this, needs more.

Real case: Galton's bean machine

In 1874 the scientist Francis Galton built a device to demonstrate this idea, now called a Galton board. Balls drop through rows of pegs, bouncing left or right at each one, and pile up in bins at the bottom. Each ball's final position is the sum of many small random left-or-right steps, a binomial count, and the piles form a bell curve. Galton wrote about it in his 1889 book Natural Inheritance. Sums and averages of many small random effects tend towards the normal: that's the central limit theorem, built from wood and pins.

Back to DeliverFast: three continuous questions

Day 9 ended with an ops meeting at DeliverFast, the food delivery startup. The team is back with three questions about measurements rather than counts.

"How far do our deliveries travel?" In one zone, suppose distances are roughly uniform between 1 and 6 km: Uniform(1, 6). Mean 3.5 km; 20% are under 2 km and 20% over 5 km, which helps set fair delivery-fee tiers.

"How often do we break the 40-minute promise?" Delivery times average 28 minutes with an SD of 6, and the histogram looks roughly bell-shaped: Normal(28, 6). A 40-minute delivery is z = 2, so about 2.3% of deliveries break the promise through ordinary variation alone. (If the histogram had a long right tail, a normal model would understate this.)

"At our busiest restaurant, how long between new orders?" Orders arrive with an average gap of 4 minutes: Exponential with mean 4. P(next order within 2 minutes) ≈ 39.3%; P(a 10-minute lull) ≈ 8.2%, long enough for the kitchen to catch up.

Pythondistance = stats.uniform(loc=1, scale=5) delivery = stats.norm(loc=28, scale=6) next_order = stats.expon(scale=4) print(f"P(distance under 2 km): {distance.cdf(2):.1%}") print(f"P(distance over 5 km): {distance.sf(5):.1%}") print(f"P(delivery over 40 minutes): {delivery.sf(40):.1%}") print(f"P(next order within 2 min): {next_order.cdf(2):.1%}") print(f"P(no new order for 10 min): {next_order.sf(10):.1%}")
OutputP(distance under 2 km): 20.0% P(distance over 5 km): 20.0% P(delivery over 40 minutes): 2.3% P(next order within 2 min): 39.3% P(no new order for 10 min): 8.2%

Same company, same kind of meeting as Day 9, but every question this time is about a distance or a duration. Recognising the shape of the process is still the real skill.

What comes next

Every example so far assumed we already knew the true parameters: p, λ, μ, σ. Real data science almost never works that way. You don't know the true conversion rate or the true average delivery time. You have a sample, and you want to work back to what's true about the whole population. That's statistical inference, and it's where the series goes next. The central limit theorem you met today is what makes most of it possible.

Key takeaways

Quick check

Five questions to test whether this stuck. The answers are one click away.

A number is drawn uniformly between 0 and 100. What's the probability it's exactly 50?

0. For any continuous random variable, any single exact value has probability 0. Only ranges, such as "between 49.5 and 50.5" (1%), have non-zero probability.

Delivery times are roughly normal with a mean of 28 minutes and an SD of 6. About what share take between 22 and 34 minutes?

About 68%. 22 and 34 are each 1 standard deviation from the mean, so this is the 68-95-99.7 rule's first band.

Requests arrive at 30 per minute. A colleague writes stats.expon(scale=30) to model the gap between requests. What's wrong?

SciPy's scale is the mean gap, 1/λ, not the rate. 30 per minute means a mean gap of 1/30 of a minute (2 seconds), so it should be stats.expon(scale=1/30). As written, it models an average gap of 30 minutes.

Why are the Poisson rate and the exponential mean reciprocals of each other?

They describe the same process from two angles. If events happen at λ per hour (Poisson), the average wait between them is 1/λ hours (exponential). More events per hour means shorter gaps.

You take many samples of size 50 from a heavily skewed population and plot their means. Will the plot still look heavily skewed?

Much less so. By the central limit theorem, the distribution of sample means moves towards normal as the sample size grows, whatever the population's shape. In this article's simulation, averaging 40 values cut the skewness from 2.0 to about 0.3.

Next up, Day 11 From Samples to Certainty

Part III begins: sampling, the central limit theorem in depth, standard errors, confidence intervals and the bootstrap, or how to learn the truth about a population from a sample.