The Distribution Zoo, Part 1: The Core Distributions
A bell curve is a fine default, until you model response times with it and predict that 2 in 60 requests finish in negative time. Every distribution is a story about how data got generated: waiting for a bus, flipping a weighted coin, adding up squared errors, multiplying small random effects. Learn the stories and you can look at a column of numbers and say which distribution it probably came from.
After this lesson, you will be able to:
Explain how the loss function you train with (squared error, absolute error, cross-entropy) is the negative log of a distribution you assumed for the target
Describe the generating story, the parameters, the mean and the variance of the Uniform, Exponential, Beta, Dirichlet, Categorical, Multinomial and Student-t distributions
Use the memoryless property and the Poisson link to turn event counts into waiting times, and the other way round
Read a Beta distribution as a tally of successes and failures and update it with data, then generalise the same idea to k classes with a Dirichlet
Explain why a small sample needs the Student-t multiplier instead of 1.96, and confirm it with a simulation of interval coverage
Pick a first candidate distribution from the type of a single data point, using the story table
Choosing a distribution is a modelling decision, not a formality. Pick the shape that matches how the data was generated and everything downstream (loss functions, confidence intervals, anomaly thresholds) gets better for free.
You have already met three of the animals. In the Descriptive Statistics lesson you saw the Normal, the Bernoulli, the Binomial and the Poisson. In the Random Variables lesson you learned that a PMF gives probabilities for countable values, a PDF gives density for continuous ones, and a CDF accumulates them. This lesson does not repeat those. It adds the most useful of the rest of the zoo and, more importantly, teaches you to choose.
#The Payoff First: Every Loss Function Hides a Distribution
Here is the reason this lesson matters for machine learning. When a model predicts and reality answers, you need one number for how bad the prediction was. The principled number is the negative log of the probability the model gave to what actually happened (for a continuous number such as a price, it is the negative log of the density at the true value, and a density is not a probability). Add it up over the data and you have the negative log-likelihood, and training minimises it. Three tiny cases show what comes out.
Yes or no. A classifier says a click has probability 0.8, and a click happens. The loss is −ln 0.8 = 0.223. Had it said 0.1, the loss would be −ln 0.1 = 2.303, ten times worse. That is binary cross-entropy, and the story behind it is the Bernoulli.
A number with Normal noise. A regression model predicts 1, the truth is 3, and the noise has standard deviation 1. The negative log of the Normal density at 3 is ½ × (3 − 1)² + 0.919 = 2.919. The 0.919 never changes with the prediction, so training only feels the squared error. That is mean squared error, and the story is the Normal.
A number with Laplace noise. The Laplace distribution has a sharper peak than the Normal and fatter tails, and its density is ½e^(−|x − μ|) when its scale is 1. The same prediction gives −ln(½e^(−2)) = 2 + ln 2 = 2.693: the absolute error plus a constant. That is absolute error (L1), and the story is the Laplace.
One coin, three losses. Take one coin. Your model says heads has probability 0.8. Flip it twice: heads, then tails. Score each flip three ways, each way assuming a different kind of noise. For the last two, the plain number 1 stands for heads and 0 for tails, the noise has scale 1, and the constants are dropped.
Flip
Bernoulli (cross-entropy)
Normal (half squared error)
Laplace (absolute error)
Heads (y = 1)
−ln 0.8 = 0.2231
½(1 − 0.8)² = 0.0200
gap 1 − 0.8 = 0.2000
Tails (y = 0)
−ln 0.2 = 1.6094
½(0 − 0.8)² = 0.3200
gap 0.8 − 0 = 0.8000
All three rise when the model is more surprised, so tails costs more than heads in every column. The columns are on different scales, so compare down a column, never across. Only the first column is the honest story for a coin, because a Bernoulli puts all its probability on 0 and 1.
Over several flips the probabilities multiply, and the loss adds. For heads, heads, tails the model gave 0.8 × 0.8 × 0.2 = 0.128, and −ln 0.128 = 2.0557. That equals 0.2231 + 0.2231 + 1.6094. This is why training sums per-example losses: the sum is the negative log-likelihood of the whole dataset.
The same thread returns twice. In Information Theory the average of this loss is cross-entropy, measured against the truth. In Matrix Calculus and Backprop the gradient of the cross-entropy loss comes out as prediction minus answer.
If the target is
Assume this distribution
The loss you get
Yes or no
Bernoulli
Binary cross-entropy
One of k classes
Categorical
Cross-entropy on the softmax output
A count of events
Poisson
Poisson loss, λ − y ln λ (plus a constant)
A real number, symmetric noise
Normal
Squared error
A real number, spiky noise
Laplace
Absolute error
A real number with outliers
Student-t
A loss that grows slowly for big errors
The last row has numbers too. A warning on the numbers: the 2.919 above kept the constant 0.919, but the 200 and the 13.2 below drop their constants, so do not compare them with 2.919 or with each other. Only differences between models scored on the same data, with the same convention, mean anything. Move a prediction 20 standard units away from the truth. Squared error charges 200. A Student-t loss with 5 degrees of freedom and scale 1 charges about 13.2, so one wild point cannot dominate training. Priors work the same way: a Normal prior on the weights adds an L2 penalty, and a Laplace prior adds an L1 penalty (the MLE, MAP and Fisher Information lesson shows why).
Loading visualization...
Every row of the table is a short derivation: write the log of the density, flip the sign, and throw away whatever does not depend on the prediction. Open the rows you want to check. In all of them y is the true value and the model's prediction is called mu (or p, or lambda).
So choosing a distribution is choosing a loss. The rest of the lesson is about choosing well.
Look at one data point and ask what it is. This short table is your first filter, and the full guide with parameters comes in Part 2, after you have met each story.
One data point looks like
Try this story
Yes or no
Bernoulli (add many up and you get a Binomial count)
A count: 0, 1, 2, … events in a window
Poisson
A positive time until something happens, with no memory
Exponential
A number between 0 and 1 that is itself a probability
Beta (one probability) or Dirichlet (several that sum to 1)
One label out of k
Categorical (counts of labels: Multinomial)
Any real number, errors symmetric
Normal (with outliers or very few samples: Student-t)
Every entry below follows the same five-part template: story (how the data gets made), parameters, mean and variance, a number you can check by hand, and where it shows up in ML.
Warm up with the Poisson, because the Exponential section turns it inside out. Set λ = 2 and read the bar heights: P(0) is about 0.135, P(1) and P(2) are both about 0.271, and P(3) is about 0.180.
Loading visualization...
Remember these four numbers. They return in the Exponential section, where the same λ = 2 describes the gaps between events instead of the counts.
Story. A number is drawn from an interval and no region is favoured. A random-number generator, a spinner, a shuffled index.
Parameters. Lower bound a and upper bound b. The density is flat: f(x) = 1/(b − a) on [a, b], and zero elsewhere.
E[X]=2a+b,Var(X)=12(b−a)2
Why does the uniform have these two values? The derivation uses only the flat density and two integrals.
Number example. Xavier (Glorot) initialisation for a layer with 256 inputs and 256 outputs (the fan-in and fan-out) draws weights from Uniform(−L, L) with L = √(6 / (256 + 256)) ≈ 0.1083. The variance is (2L)²/12 = 0.0039, which equals 2/(fan_in + fan_out) = 2/512. The width of the interval was chosen so that this variance keeps signal sizes stable from layer to layer.
ML appearance. Random initialisation, random sampling of mini-batches and hyper-parameter search all start from uniform draws. Uniform is also the engine behind every other sampler: draw U ~ Uniform(0, 1), push it through the inverse CDF of any distribution, and you get a sample from that distribution. The inverse CDF is the CDF run backwards: give it a probability such as 0.5 and it returns the value with that much probability below it, here the median. That trick is called inverse transform sampling, and you will use it on the Exponential next.
Story. Events arrive at a steady average rate, independently of each other: support tickets, packets, clicks. The Poisson distribution counts how many arrive in a fixed window. The Exponential measures the gap until the next one.
Parameters. Rate λ (events per unit time). Density f(t) = λe^(−λt) for t ≥ 0.
E[T]=λ1,Var(T)=λ21,P(T>t)=e−λt
The three formulas come from a density and three short integrals. Open the derivation to see where each one comes from.
Number example. Tickets arrive at λ = 2 per minute. The average gap is 0.5 minutes and the standard deviation is also 0.5. The chance of waiting more than a minute is e^(−2) ≈ 0.1353. Notice that this is exactly the Poisson P(0) you read off the slider above, and it must be: "no ticket in the next minute" and "the next gap is longer than a minute" are the same event.
What Do You Think?
Support tickets arrive randomly, and the gaps between them are Exponential with an average of 5 minutes. It has now been 20 minutes since the last ticket. How much longer do you expect to wait for the next one?
The memoryless property. For an Exponential, P(T > s + t | T > s) = P(T > t). Check it with λ = 2: P(T > 3 | T > 2) = e^(−6) / e^(−4) = e^(−2) ≈ 0.1353, the same as P(T > 1). The past waiting time carries no information about the future, because the underlying events are independent. It is the only continuous distribution with this property.
Why is the Exponential memoryless? It follows from the survival function in one line of algebra.
Sampling it. The Exponential's CDF is F(t) = 1 − e^(−λt). Set U = F(t) for U ~ Uniform(0, 1) and solve for t: T = −ln(1 − U)/λ, which is the inverse CDF from the Uniform section at work. With λ = 2 and U = 0.5 you get T = 0.3466 minutes, which is the median gap (ln 2 / λ). Half of all gaps are shorter than 0.35 minutes even though the mean is 0.5; the distribution is right-skewed.
How is a uniform random number turned into an Exponential one? The derivation shows why the formula T = -ln(1 - U)/lambda works.
ML appearance. Time-to-event models in survival analysis start from the Exponential, which has a constant hazard rate (the same chance of the event in the next instant, however long you have waited). Queueing models for model-serving capacity assume exponential inter-arrival times. In reinforcement learning, continuous-time MDPs use exponential holding times, and in simulation it is the default way to generate random event times.
Story. You want to describe your belief about an unknown probability p, such as a click rate. Every value of p lives in [0, 1], and you want the shape to sharpen as evidence arrives. The Beta distribution is exactly a density on [0, 1].
Parameters. Two positive numbers a and b. The cleanest way to read them: start from the flat curve Beta(1, 1), which means "nothing seen yet", then add 1 to a for every success and 1 to b for every failure. So Beta(a, b) behaves like a notebook holding a − 1 successes and b − 1 failures.
Two readings of the centre differ slightly, and it pays to keep them apart. The most likely value (the mode) is (a − 1)/(a + b − 2), which is exactly the raw success rate in the notebook. The mean a/(a + b) is pulled toward 0.5, because it behaves as if the notebook also held one extra success and one extra failure.
Three results sit behind the Beta formulas: the mean and variance, the mode, and the update by addition. Open any of them.
Number example. Start with Beta(2, 2): mean 0.5, standard deviation 0.224, which is the flat start plus one imagined success and one imagined failure, a mild belief that the rate is near the middle. Observe 8 clicks and 2 non-clicks. The posterior is Beta(2 + 8, 2 + 2) = Beta(10, 4), a notebook with 9 successes and 3 failures. Its mode is 9/12 = 0.75, its mean is 10/14 = 0.714, its standard deviation is 0.117, and its 95% interval runs from 0.462 to 0.909. The raw rate 8/10 = 0.8 got pulled toward the prior. The exercise at the end adds 50 more observations, and you will watch the interval tighten.
Updating beliefs this way is the whole subject of the Bayesian Inference in Practice lesson, which covers priors, credible intervals and A/B tests properly. Here you only need the shape, the mean, and the update-by-addition rule.
Use the explorer to confirm the formulas above. Choose Beta and watch the mean, variance and mode readouts as you move α and β.
Try it: switch families and move the slidersInteractive
Loading visualization...
Try this: Select Exponential and set λ = 2; the readout should show mean 0.5 and variance 0.25. Select Beta and set α = 2, β = 5 and confirm the mean is 2/7 = 0.286. Then set α = 4 and β = 10 (the slider maximum is 10) and compare with α = 2, β = 5: the mean stays at 0.286 but the curve tightens, which is what more evidence looks like. Select Uniform with a = 0, b = 1 and confirm the variance reads 0.083.
ML appearance. Thompson sampling for bandits keeps a Beta for every arm's success rate, samples one value from each, and plays the highest. The Beta prior is also how Bayesian A/B testing talks about conversion rates.
Quick check
You observe 3 successes and 1 failure with a flat Beta(1, 1) prior. What is the posterior and its mean?
Story. Instead of one probability you need a whole probability vector: three topic proportions, or the class probabilities of a classifier. Each entry is non-negative and they sum to 1. The set of all such vectors is called the simplex; for three classes it is a triangle whose corners are "all class A", "all class B" and "all class C". The Dirichlet is a distribution over points of the simplex. With k = 2 it is the Beta.
Parameters. One pseudo-count per class: α = (α₁, …, α_k), with α₀ = α₁ + … + α_k. As with the Beta, bigger numbers mean more evidence.
Python draws of 100,000 points show it. With alphas (20, 20, 20) the largest share averages 0.398 and never passes 0.9. With (1, 1, 1) it averages 0.61 and passes 0.9 in 3% of draws. With (0.2, 0.2, 0.2) it averages 0.821 and passes 0.9 in 45% of draws.
Loading visualization...
One counting rule, same as Beta. The imagined observations are alpha minus 1, and alpha = 1 for every class is the flat start. Beta(2, 2) imagines one success and one failure. Dirichlet(2, 3, 5) imagines 1, 2 and 4 observations of the three classes, 7 in all.
Where the formulas come from. Look at one entry p_i and lump all the other classes together as "not i". The Dirichlet then reduces to a Beta(α_i, α₀ − α_i), so the mean and variance above are just the Beta formulas with a = α_i and b = α₀ − α_i. The covariance comes from lumping two classes together, as the derivation below shows: the shares always add to 1, so the covariances are negative.
The covariance is the interesting one, and it is derived by lumping classes together. Open the derivation for each step.
Number example. Dirichlet(2, 3, 5) has α₀ = 10. The expected proportions are (0.2, 0.3, 0.5). The variance of the first entry is 2 × 8 / (100 × 11) = 0.01455 (standard deviation 0.121), and the covariance between the first two is −2 × 3 / (100 × 11) = −0.00545, negative as it must be. Check the sum-to-1 rule: the three variances (0.01455, 0.01909, 0.02273) add to 0.05636, the three covariances (−0.00545, −0.00909, −0.01364) add to −0.02818, and 0.05636 + 2 × (−0.02818) = 0 exactly. Multiply every α by 10 and the means are unchanged but the standard deviations shrink to about a third.
ML appearance. A softmax output is one point on the simplex, which is exactly where a Dirichlet lives. A Dirichlet is what you reach for when you want to say how unsure you are about the probabilities themselves. Latent Dirichlet Allocation (a topic model that treats each document as a mix of topics) draws each document's topic mix, and each topic's word mix, from Dirichlet priors. With all α below 1, samples concentrate near the corners: documents mostly about one topic.
Story. A Categorical distribution is one draw from k classes with probabilities p₁, …, p_k: a die roll, a predicted token, a softmax output sampled once. A Multinomial repeats that n times and records the count per class. Bernoulli and Binomial are the k = 2 cases.
Parameters. The probability vector p (summing to 1), and for the Multinomial also the number of draws n.
Two results sit behind the multinomial formula: the probability of one set of counts, and the mean and variance of each count.
Number example. Ten draws from p = (0.5, 0.3, 0.2). The expected counts are (5, 3, 2). The probability of landing on exactly (5, 3, 2) is 10! / (5! 3! 2!) × 0.5⁵ × 0.3³ × 0.2² = 2520 × 0.03125 × 0.027 × 0.04 = 0.08505, about 8.5%. Even the single most likely outcome happens less than one time in ten. The softmax of logits (2, 1, 0.1) gives the categorical distribution (0.659, 0.242, 0.099).
ML appearance. The categorical is the output distribution of every classifier and of every language model (the next token is one categorical draw over the vocabulary). Cross-entropy loss is the negative log of the probability the categorical gave to the true class, as in the table at the top: with these probabilities, a true class 1 costs −ln 0.659 = 0.417 and a true class 2 costs 1.417. Bag-of-words models and Naive Bayes treat a document's word counts as one Multinomial draw.
Story. You estimate a mean from a small sample and must also estimate the spread from the same few points. That extra uncertainty makes the standardised mean fatter-tailed than a Normal. The Student-t is the distribution of (sample mean − true mean) / (s/√n) when the data is Normal, and it is also a model of its own for data with outliers.
Degrees of freedom, by hand. Take three values with a known average of 6: 4, 6 and 8. Once you pick any two, the third is forced, because the three must still average 6. So only 2 of the 3 are free. The spread estimate uses the distances from the average, so it carries n − 1 = 2 degrees of freedom. More free values means a steadier spread estimate and a thinner tail.
Number example (three values). For 4, 6, 8 the average is 6 and the sample standard deviation is s = 2, so s/√3 = 1.1547. The normal 1.96 multiplier would give 6 ± 2.26. The t multiplier for 2 degrees of freedom is 4.303, which gives 6 ± 4.97, or about 1.03 to 10.97. A ratio beyond 1.96 in either direction happens 18.9% of the time with 2 degrees of freedom, against 5.0% for the bell curve.
Loading visualization...
The Student-t was defined above as a ratio. The next derivation shows how the standardised sample mean becomes a Normal divided by a Chi-square.
Parameters. Degrees of freedom ν (for the t-test, ν = n − 1). As ν grows, it converges to the standard Normal. Small ν means thick tails. At ν = 1 it is the Cauchy distribution, which has no mean at all.
E[T]=0(ν>1),Var(T)=ν−2ν(ν>2)
Why is the t variance nu over nu minus 2? The derivation uses the ratio form and one Gamma-function integral.
Number example (tails). How likely is a value more than 4 standard units from zero? For a standard Normal it is 0.0000633, about 1 in 15,800. For a t with ν = 5 it is 0.0103, about 1 in 97. That is roughly 163 times more likely. The variance of t₅ is 5/3 = 1.667, so even the typical spread is 29% wider than a standard Normal's standard deviation of 1 (√1.667 = 1.29). Those fat tails are why the Student-t loss in the table at the top forgives big errors.
Number example (the t-test). The 95% two-sided multiplier is 1.960 for a Normal. For a t it depends on the sample size: 12.71 with n = 2, 4.30 with n = 3, 2.776 with n = 5, 2.262 with n = 10, 2.045 with n = 30. If you used 1.96 on samples of size 5, your "95%" intervals would miss the true mean about 12% of the time in simulation (they would cover only about 88%); the t multiplier brings coverage back to 95%. Run the cell below to see it yourself.
A Pyodide-backed scratchpad for math lessons.
Loading visualization...
ML appearance. The t-test (from the Statistical Inference lesson) is the Student-t at work: comparing two models over a handful of cross-validation folds. Student-t likelihoods give regression models robustness to outliers, and t-SNE uses a t distribution with ν = 1 in the low-dimensional space precisely because its heavy tails let clusters separate cleanly.
These are the distributions the later lessons on sampling, inference and Bayesian updating use again. Each row repeats numbers you checked by hand above, and Part 2 draws 10,000 seeded samples from every one of them to confirm the formulas. The Categorical is the single-draw version of the Multinomial row, so it needs no row of its own.
Tests: After day 1 the posterior is Beta(10, 4) with mean 0.714. After day 2 it is Beta(50, 14) with mean 0.781 and sd 0.051, and the 95% interval 0.673 to 0.873 is narrower than after day 1. The mode is 0.790, closer to the raw rate 0.8 than the mean 0.781. The conditional exponential survival ratio equals sf(5), about 0.3679. The loss is 0.2231 at a predicted 0.8 and 2.3026 at a predicted 0.1.
When you run the solution you should see Beta(10, 4) with mean 0.714 after day 1, then Beta(50, 14) with mean 0.781 and standard deviation 0.051 after day 2. The 95% interval tightens from 0.462 to 0.909 down to 0.673 to 0.873: more evidence, tighter belief. The mode 0.790 sits closer to the raw rate 0.800 than the mean 0.781 does, as the notebook reading predicts. The memoryless ratio and sf(5) both print 0.3679. The loss is 0.2231 when the model said 0.8 and 2.3026 when it said 0.1.
Every distribution is a story, and your loss function already assumed one — Normal gives squared error, Laplace absolute error, Bernoulli binary cross-entropy, Categorical cross-entropy; Exponential is the gap between random events, Beta is a belief about a probability, Dirichlet is a belief about a probability vector
Exponential is memoryless and its standard deviation equals its mean — with rate 2 per minute the mean gap is 0.5 minutes, P(T > 1) = 0.1353, and that equals the Poisson probability of zero events
Beta parameters are a notebook of tallies and updating is addition — Beta(2, 2) plus 8 clicks and 2 misses becomes Beta(10, 4), mode 0.75 and mean 0.714; the Dirichlet does the same for k classes, and a softmax output is a point on its simplex
Small samples and outliers need the Student-t — with n = 5 the 95% multiplier is 2.776, not 1.96, and the t has variance ν/(ν − 2)
You train a regression model with mean absolute error (L1) loss. Which noise story are you implicitly assuming for the target?
Next up: The Distribution Zoo, Part 2: Fitting Data and Heavy Tails. You will meet the Lognormal, Gamma, Chi-square and power laws, learn the four tools that check a fit, and fit 60 API response times.
Up next
The Distribution Zoo, Part 2: Fitting Data and Heavy Tails