Standard deviation measures how tightly values cluster around their mean. A small standard deviation means observations tend to stay close to the average; a large one means they wander farther away. Unlike variance, standard deviation is expressed in the original measurement units, which makes it easier to read in everyday terms: degrees, pounds, inches, or grams. section 2.17 section 2.19
It is simply the nonnegative square root of variance. Variance starts by finding each value’s difference from the mean, squaring those differences, and averaging them. Taking the square root undoes the unit-squaring, turning the result back into a useful measure of typical spread. section 2.18 section 2.19
March temperatures
For 31 daily high temperatures, the mean is 75.48 degrees and the sample standard deviation is about 7.59 degrees. Saying temperatures varied by 7.59 degrees is much more intuitive than reporting a variance of 57.66 squared degrees. A from-scratch function can calculate sample variance using n − 1, then apply a square root; NumPy produces the same sample result with np.std(data, ddof=1). section 2.18 section 2.19
Use standard deviation to make spread part of the question, not an afterthought:
- Compare consistency around an average, such as collie weights, where wider spread can complicate standardized treatments and dosages. section 2.17
- Assess predictability: data with more variability around its center can lead to less consistent model predictions. section 2.18
- Set the width of a normal distribution: larger standard deviations create wider, more variable bell curves, while smaller ones create narrower, more predictable curves. section 4.1 section 4.2
- Prefer the interquartile range when outliers skew the data or when the normal-distribution assumption does not fit. section 2.19
Coffee preferences are spread, too
A survey of 78 baristas asks for the ideal grams of grounds in a 16-fluid-ounce pour-over coffee. The responses have a mean of 27.6 grams, a median of 28.0 grams, and a sample standard deviation of 3.2 grams. The standard deviation summarizes how much opinions vary around the typical recommendation, while the survey’s local focus can introduce bias. section 4.3
import numpy as np
from math import sqrt
temps = [77,75,68,71,60,65,81,71,56,73,
79,80,85,84,72,69,82,81,71,63,
75,83,80,80,88,76,79,73,80,81,82]
def variance(data: [int]):
# calculate mean
mean = sum(data) / len(data)
# sum all the squared differences
squared_diffs = 0
for x in data:
squared_diffs += (x - mean) ** 2
# take the average of the squared differences
return squared_diffs / (len(data) - 1)
# just take the square root of variance
def standard_deviation(data: [int]):
return sqrt(variance(data))
# Standard Deviation: 7.5932907567226104
print("Standard Deviation: ", standard_deviation(temps))
# From NumPy: 7.5932907567226104
print("From NumPy: ", np.std(temps, ddof=1))
The listing makes the calculation concrete: compute sample variance, take its square root, then compare the result with NumPy’s std using ddof=1. section 2.19














