Statistics
Standard score (z-score)
stats.z-scoreAlso called z score, zscore, standard score, standardize
where
where
Each observation's distance from the mean, in units of the standard deviation. The default δ = 0 uses the population standard deviation, as scipy.stats.zscore and scikit-learn's StandardScaler do; δ = 1 uses the sample standard deviation.
Notation
observations
x ∈ ℝn
delta degrees of freedom in the standard deviation's divisor n − δ
δ ∈ {0, 1} · default 0 · also common: 1
number of observations
Size, at least 2
Result: the standardized values
vector
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
≈ (-1.5, -0.5, -0.5, -0.5, 0, 0, 1, 2)
Given
Result
Given
Result
≈ (-1.16189500386, -0.387298334621, 0.387298334621, 1.16189500386)
Common mistakes
Divides by σ without subtracting the mean
The values are scaled but not centered.
Fix: Subtract the mean before dividing.
Divides by the variance
The deviations are divided by σ2 instead of σ.
Fix: Divide by the standard deviation, the square root of the variance.
Source
Casella and Berger 2002
Casella, George; Berger, Roger L. Statistical Inference. 2nd ed. Duxbury, 2002.