Skip to content
AI360Xpert
Glossary
Definition

Variance

The average squared distance of a random variable from its own mean — how widely values scatter.

Variance is E[(XE[X])2]E[(X - E[X])^2]: take each value's distance from the mean, square it, average the squares. Squaring stops positive and negative deviations cancelling and makes far-away points count much more than near ones, which is why variance is sensitive to outliers.

Two mistakes are worth knowing about because both are silent. There are two variances — dividing by nn gives the population version, dividing by n1n-1 gives the sample version, and NumPy defaults to nn while pandas defaults to n1n-1. At eight data points the two differ by about 14%, which matters exactly when you are comparing models across a handful of cross-validation folds.

And never compute it as E[X2]E[X]2E[X^2] - E[X]^2. With large means those two terms agree in their leading digits and the subtraction destroys all precision, frequently returning a negative variance — which is impossible for an average of squares. A negative variance always means this.