The Math Behind the Methods

The Gaussian Distribution in Machine Learning and Its Limits

Why the bell curve appears throughout machine learning, how its multivariate form works, and when assuming it will mislead you.

Key takeaways

  • A Gaussian is fixed by its mean and covariance, and linear transformations, marginals and conditionals of Gaussians remain Gaussian.
  • Squared error is the negative log likelihood of Gaussian noise with constant variance.
  • The central limit theorem concerns sums and averages of many modest independent effects, not raw data in general.
  • Gaussian tails are very light, so a model that assumes them can badly underrate extreme events and be dragged around by outliers.
  • In high dimensions, Gaussian samples lie near a thin shell far from the mean, which defies low-dimensional intuition.

The Gaussian, or normal, distribution is the symmetric bell curve described completely by a mean and a variance, or in many dimensions by a mean vector and a covariance matrix. Machine learning uses it for noise, priors, initial weights, latent codes and more, largely because it makes the mathematics unusually tidy.

The tidiness is also the risk. A Gaussian says that large deviations are extraordinarily rare and that one hump describes everything. Many real quantities disagree.

One dimension

The density with mean μ and standard deviation σ > 0 is:

p(x) = exp( −(x − μ)² / (2σ²) ) / √(2πσ²)

The quantity z = (x − μ)/σ counts standard deviations from the mean. About 68% of the probability lies within |z| ≤ 1, about 95% within |z| ≤ 2 and about 99.7% within |z| ≤ 3.

Take the negative natural logarithm and you get (x − μ)²/(2σ²) + ½ ln(2πσ²). If σ is fixed and μ is a model's prediction, minimizing this over a dataset is the same as minimizing squared error. If the model predicts σ too, the loss weighs each error by the predicted noise and charges a logarithmic price for claiming large uncertainty. That is a simple way to model noise that varies with the input.

Why it keeps appearing

  • Sums of small effects. The central limit theorem says that a suitably standardized average of many independent variables with the same distribution and finite variance approaches a Gaussian.
  • Least commitment. Among all densities on the real line with a given mean and variance, the Gaussian has the greatest entropy, a measure of how spread out and uncommitted a distribution is.
  • Closure. Adding independent Gaussians gives a Gaussian, with means and variances added. So does any linear transformation.
  • Calculation. Its log density is a quadratic, so fitting and updating often reduce to linear algebra.

The first reason has conditions. If one effect dominates, if effects multiply, if they are strongly dependent or if their variance is infinite, the conclusion can fail. Multiplied effects, for instance, tend toward a log-normal shape.

Many dimensions

For a vector x with d entries, mean μ and a positive definite covariance matrix Σ of shape (d, d), the density depends on x only through one number:

D² = (x − μ)ᵀ Σ⁻¹ (x − μ)
p(x) = exp(−D²/2) / √( (2π)ᵈ det Σ )

D is the Mahalanobis distance: distance measured in units of the data's own spread and correlation. Consider two unit-variance features with correlation 0.8 and mean zero.

Σ = [[1, 0.8], [0.8, 1]]      Σ⁻¹ = (1/0.36) · [[1, −0.8], [−0.8, 1]]

point (1, 1):    D² = (2 − 1.6)/0.36 = 1.11
point (1, −1):   D² = (2 + 1.6)/0.36 = 10

Both points are the same Euclidean distance from the center. The first agrees with the correlation and is ordinary. The second contradicts it and is far more surprising. Anomaly detectors built on a Gaussian exploit exactly this.

The covariance must be positive definite for this density to exist, a property discussed in positive definite matrices. A full covariance has d(d + 1)/2 free numbers, so with many features people restrict it to a diagonal, a low-rank part plus a diagonal, or a shrunken estimate.

Slicing and projecting

If x and y are jointly Gaussian, the distribution of x alone is Gaussian, and so is the distribution of y after observing x. For two standardized variables with correlation ρ:

y | x  ~  Normal( ρx,  1 − ρ² )
with ρ = 0.8 and x = 2:   mean 1.6,  variance 0.36

The mean moves linearly with the observed value, and the uncertainty shrinks by an amount that does not depend on that value. This pair of facts powers Gaussian process regression, Kalman filters and Bayesian linear regression.

Where models use it

Use What is assumed Gaussian
Least squares regression, read probabilistically Noise around the prediction
L2 penalty, read as a prior The weights before seeing data
Mixture models Each cluster
Linear discriminant analysis Features within each class, with shared covariance
Variational autoencoders, common setup The latent prior and approximate posterior
Diffusion models, common setup The noise added at each step

In the last two rows the Gaussian is a design choice about a variable the modeler controls, which is safer than a claim about nature. The data distribution they produce can be far from Gaussian.

The tails

Gaussian tails fall off faster than exponentially. A deviation beyond 3 standard deviations in either direction has probability about 0.27%. Beyond 5, it is less than one in a million.

Compare a Laplace distribution with the same variance of 1. The chance of exceeding 5 in magnitude is exp(−5√2), about 0.085%, which is more than a thousand times the Gaussian figure. Distributions with power-law tails put still more weight out there.

If your data include fraud amounts, network delays, insurance losses or price jumps, a Gaussian fit can call routine extremes impossible. The fit also suffers, because the squared penalty lets a few large values pull the mean and inflate the variance. Huber loss and Student t noise models reduce that pull.

Safer and riskier uses of a Gaussian assumption
Often reasonable Averages of many small independent effects Noise you add yourself by design Residuals that pass a quantile check A first prior on well-scaled weights Often misleading Skewed amounts that cannot be negative Several separate groups mixed together Heavy-tailed losses or delays Counts that are mostly zero VS Often reasonable Averages of many small independent effects Noise you add yourself by design Residuals that pass a quantile check A first prior on well-scaled weights Often misleading Skewed amounts that cannot be negative Several separate groups mixed together Heavy-tailed losses or delays Counts that are mostly zero

Shapes it cannot express

A single Gaussian is symmetric and has one peak. It gives some probability to every real value, including negative ages and proportions above 1. It cannot represent two distinct modes: fitted to them, it puts its highest density in the empty space between.

Remedies include transforming the variable, choosing a distribution with the right range, or combining several components, as in Gaussian mixture models. Correlation also captures only linear association. Two variables can each look Gaussian while their joint behavior is not, especially in how extremes coincide.

High-dimensional surprises

Draw x with d independent standard Gaussian entries. The squared length has mean d and variance 2d, so the length concentrates near √d with a spread that stays below 1. For d = 1,000, nearly all samples sit at a distance of about 31.6 from the origin.

The density is highest at the origin, yet samples almost never land near it, because there is so little volume there. Interpolating linearly between two random latent vectors passes through points with unusually short length, which is why some generative modelers interpolate along an arc instead. Independent random directions are also close to perpendicular.

Fitting one, and what can go wrong

Maximum likelihood fitting of a Gaussian is direct. The estimate of the mean is the sample average, and the estimate of the covariance is the average outer product of the centered examples.

μ̂ = (1/n) ∑ xᵢ
Σ̂ = (1/n) ∑ (xᵢ − μ̂)(xᵢ − μ̂)ᵀ

Dividing by n − 1 instead of n gives the unbiased version of the covariance. With large n the difference is negligible.

The harder problem is dimension. If n ≤ d, the estimated covariance cannot have full rank, so its inverse and the density do not exist. Even when n is somewhat larger than d, the smallest eigenvalues tend to be underestimated, and the Mahalanobis distance divides by exactly those. Ordinary points can then look wildly unusual along directions that the sample barely explored.

Common remedies are to add a small multiple of the identity matrix, to blend the estimate with a diagonal matrix, or to reduce the dimension first. Choose the amount on held-out likelihood or on the downstream task.

For numerical stability, do not form the inverse or the determinant directly. A Cholesky factorization Σ = LLᵀ gives D² as the squared length of the solution z of Lz = x − μ, and ln det Σ as twice the sum of the logarithms of the diagonal of L. The same factor lets you sample: draw standard Gaussian entries z and return μ + Lz.

Checking before trusting

Look at the data before you test it. A quantile-quantile plot compares sorted standardized residuals with Gaussian quantiles. Points bending away at both ends signal heavy tails, and a curve signals skew.

import numpy as np

rng = np.random.default_rng(0)
gauss = rng.normal(size=200_000)
heavy = rng.standard_t(df=3, size=200_000) / np.sqrt(3)   # variance 1
for name, x in [("gaussian", gauss), ("student t", heavy)]:
    print(name, np.mean(np.abs(x) > 3), np.mean(np.abs(x) > 5))

The two samples have the same theoretical variance, yet their far tails differ greatly. Formal normality tests help little on their own: with large samples they reject trivial departures, and with small samples they miss serious ones. Ask whether the departure changes a decision.

Common questions

Must my input features be Gaussian?

Usually not. Linear regression makes no such demand of the inputs, and trees ignore monotonic rescaling. Some methods, such as discriminant analysis and naive Bayes with Gaussian features, do assume a shape within each class.

Is a Gaussian assumption harmless if I only want point predictions?

Often it is tolerable, since squared error still targets the conditional mean. The intervals and tail probabilities are what suffer first. If any decision depends on how likely a large miss is, check those directly on held-out data.

Does standardizing a variable make it Gaussian?

No. Subtracting the mean and dividing by the standard deviation changes location and scale only. The shape stays the same. Log and power transforms can change shape.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 26 articles in The Math Behind the Methods →

Latest news on this topic