Mean, variance and uncertainty
The mean describes the arithmetic center of a numerical collection. Variance describes its average squared distance from that center when computed as population variance. For three observed delays [2, 4, 6] minutes and [0, 4, 8] minutes, both means are 4 minutes, but the second collection has four times the population variance. Equal averages can hide very different amounts of variation.
Calculate spread by hand
For [2, 4, 6], deviations from the mean are −2, 0 and 2 minutes. Squared deviations are 4, 0 and 4 square minutes. The population variance is 8/3 square minutes. For [0, 4, 8], squared deviations are 16, 0 and 16, so the population variance is 32/3 square minutes. Standard deviation is the square root of variance, returning to the original units. In the second group one delay is 8 minutes, whereas none in the first exceeds 6. Variance alone does not determine every tail probability.
def population_variance(values): if not values: return None mean = sum(values) / len(values) return sum((x - mean) ** 2 for x in values) / len(values)
print(round(population_variance([2, 4, 6]), 3))print(round(population_variance([0, 4, 8]), 3))print(population_variance([4, 4, 4]))print(population_variance([]))Both fixtures are treated as the entire population of interest for this descriptive calculation. The helper expects small finite numbers and returns None for an empty collection. A constant population has variance zero; a singleton also has population variance zero. For a sample used to estimate an underlying population variance, a common estimator divides by n−1 rather than n and requires at least two observations. Python’s standard library statistics.pvariance and statistics.variance distinguish these calculations. This chapter does not derive the estimator.
Random variables and distributions
A random variable assigns a numerical value to each outcome. For a uniform draw from [0, 4, 8], the delay variable X has a discrete probability distribution: P(X=0)=P(X=4)=P(X=8)=1/3. Its expected value is the probability-weighted sum 4. A different variable could represent a continuous measurement, such as an exact duration; probabilities are then commonly assigned to intervals rather than individual exact values. A distribution describes possible values and their probabilities under assumptions, not a guarantee of the next observation.
groups = [[2, 4, 6], [0, 4, 8]]for values in groups: mean = sum(values) / len(values) late = sum(1 for x in values if x > 6) print(mean, round(late / len(values), 3))The groups have equal means, but the observed frequency of delays above 6 minutes is 0 and 1/3. Neither tiny group establishes a reliable future failure rate. Use a larger representative sample before deciding that one machine is safer.
Sampling, calibration and confidence
A sample is a subset or collection of observations from a target population. Random sampling can reduce selection bias when the sampling design is appropriate, but small samples still fluctuate. Empirical frequency is an observed ratio. A subjective probability expresses a degree of belief under stated information. A calibrated forecast of 0.8 means that, among comparable predictions near 0.8, outcomes should occur roughly 80% of the time across suitable evaluation data. Calibration does not ensure any individual prediction is correct or remain valid after a population shift. A frequentist 95% confidence interval procedure aims to cover a fixed population parameter in 95% of repeated samples under its assumptions; it is not a 95% probability statement about a fixed parameter after a particular interval has been computed. Model confidence scores are not automatically either probabilities or confidence intervals.
Common mistakes and practice
Do not average variances across groups as if that always yields the pooled variance: group means and sizes matter. Do not use population variance and sample variance interchangeably. Avoid treating low spread as proof of correct measurements: a miscalibrated clock may consistently report the wrong value. Practice: compare [3, 3, 3] with [1, 3, 5]; both means are 3, with population variances 0 and 8/3. Identify a cost or threshold for which spread matters. The next chapter uses loss and optimization to choose parameters; deeper estimation and interval construction belong to Machine Learning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Mean, variance and uncertainty — understanding check
Reason about uncertainty using synthetic factory observations.
What is the mean of [0,4,8]?
What is the population variance of [2,4,6]?
Which collection has the larger population variance?
What would indicate good calibration for predictions near 0.8 on suitable evaluation data?
What does a frequentist 95% confidence interval procedure aim to achieve under its assumptions?