Skip to content

Probability and Statistics

Descriptive statistics and the Gaussian

Summarizing data: mean, variance, the bell curve

You cannot look at a million numbers at once, so you summarise them. Where is the cloud centred? How wide is it? What shape does it take? Three answers - the mean (centre), the standard deviation (width), and the Gaussian (the bell shape a great many clouds fall into) - carry almost all the everyday statistics that machine learning leans on. Get these into your fingers and terms like "normalize the features," "unit variance," and "standard normal" stop being jargon and start being pictures.

The one-line idea

Every cloud of numbers has a centre and a width. The mean marks the centre - the balance point. The standard deviation measures the width - the typical distance a value sits from that centre. Draw a smooth bell of that centre and width over the points and you have the Gaussian, the default shape of "random spread" in nature and in models.

Mean: the balance point

The mean (or average) of values is their sum divided by how many there are:

The physical picture is a seesaw. Place each data point as an equal weight along a ruler; the mean is the single spot where the ruler balances. Slide one point far to the right and the balance point drifts right to compensate - which is exactly why the mean is sensitive to outliers. It is the centre of mass of the data.

Spread: variance and standard deviation

Two clouds can share a mean yet look nothing alike - one tight, one sprawling. To capture width, measure how far each point sits from the mean, . Those gaps are positive and negative and would cancel to zero if we just added them, so we square them first, then average. That average squared gap is the variance:

Squaring fixed the sign problem but left the units wrong - if is in metres, is in metres squared. So take the square root to get back into the data's own units. That is the standard deviation , the number you actually quote as "the spread":

The bell curve and the 68-95-99.7 rule

Astonishingly often, when many small independent effects add up, the resulting spread takes one particular smooth shape: the normal distribution, or Gaussian. It is a symmetric bell, tallest at the mean and thinning out on both sides. It is written - fully pinned down by just the centre and the width - and its height at a value is

Because the bell is fixed once you know and , distances are naturally measured in standard deviations. That gives the famous 68-95-99.7 rule: about 68% of a Gaussian's values fall within of the mean, about 95% within , and about 99.7% within . Land more than three standard deviations out and you are in genuinely rare territory.

Drag the points below. Watch the mean line, the shaded band, the variance readout, and the fitted bell all respond to the cloud you build - then hit normalize to standardise it.

Mean, spread & the fitted Gaussian - drag the dots - toggle normalize
mean μ±1σ band (≈68%)fitted Gaussiandata points - drag me
mean μ9.00variance σ²8.67std σ2.94within ±1σ5/9 (56%)

Spread the dots apart and the band widens, the variance grows, and the bell flattens. Bunch them up and it all tightens. Normalize slides the whole cloud onto the origin and squeezes it to unit width - the same numbers, measured with a common ruler.

The z-score: one common ruler

To compare quantities on wildly different scales - a person's height in centimetres and their income in dollars - recast each value as "how many standard deviations from its own mean" it sits. That is the z-score:

Subtracting recenters the cloud onto ; dividing by rescales it to a spread of exactly . The transformed data always has mean and standard deviation - a standard normal if the original was Gaussian. That is precisely the motion the normalize toggle animates above.

Shape and scale are separate knobs

A Gaussian carries two independent dials - where it sits () and how wide it is (). The z-score sets both to their defaults, and , without changing the shape of the cloud at all: every point keeps its rank and relative position. This is why standardising features never destroys information - it just puts every feature on the same neutral scale so no single one dominates by accident of its units.

The four numbers in NumPy:

import numpy as np

x = np.array([4, 6, 7, 8, 9, 10, 11, 12, 14])

mu    = x.mean()                 # balance point  -> 9.0
var   = ((x - mu) ** 2).mean()   # mean squared distance -> 8.67
sigma = np.sqrt(var)             # spread, in x's own units -> 2.94

z = (x - mu) / sigma             # z-scores: recenter, then rescale
# z.mean() -> 0.0     z.std() -> 1.0
Mean, variance, standard deviation, and z-scores in nine lines.

Check yourself

What does the standard deviation of a dataset measure?

About what fraction of a normal distribution lies within one sigma of the mean?

Recall the formulas for the mean, variance, and standard deviation - and what a z-score does to a value.

These four computations are the foundation of all normalisation in ML. Try to state it, then check.

Lock it in

  • The mean is the balance point - the centre of mass of the data cloud.
  • Variance squares the gaps from the mean; standard deviation takes the root to get back to original units.
  • The Gaussian is the default bell shape: 68% within , 95% within , 99.7% within .
  • The z-score recenters to 0 and rescales to 1 - standardising features without destroying their shape.

Primary source

For the clearest ground-up walkthrough of mean, variance, standard deviation, and the normal distribution, work through Josh Starmer's StatQuest - Statistics Fundamentals playlist. For live, draggable intuition about probability and distributions, play with Brown University's Seeing Theory (Basic Probability) - the same idea of building a cloud and watching its summary numbers move.

Ask your teacher

That normalize toggle you just used is not a toy - it is feature scaling, and it runs everywhere in ML. Standardising each input feature to mean 0 / std 1 is what lets gradient descent descend in near-circular bowls instead of long skewed valleys, so it converges far faster. The very same z-score transform lives inside every transformer as LayerNorm, which normalizes each token vector to mean 0 / std 1 before the next block. Ask me why we sometimes divide variance by instead of , how the mean differs from the median for skewed data, or why sums of independent random things drift toward a Gaussian in the first place (the central limit theorem).