All formulas

Statistics

Standard score (z-score)

stats.z-scoreAlso called z score, zscore, standard score, standardize

zi=xi−xˉσz_i = \frac{x_i - \bar{x}}{\sigma}

wherexˉ=1n∑j=1nxj\bar{x} = \frac{1}{n}\sum_{j=1}^{n} x_j

whereσ=1n−δ∑k=1n(xk−xˉ)2\sigma = \sqrt{\frac{1}{n - \delta}\sum_{k=1}^{n} (x_k - \bar{x})^2}

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

xx

observations

x ∈ ℝn

δ\delta

delta degrees of freedom in the standard deviation's divisor n − δ

δ ∈ {0, 1} · default 0 · also common: 1

nn

number of observations

Size, at least 2

zz

Result: the standardized values

vector

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[1,3]x = [1, 3]

    Result

    z=(−1,1)\displaystyle z = \left(-1, 1\right)
  2. Given

    x=[2,4,4,4,5,5,7,9]x = [2, 4, 4, 4, 5, 5, 7, 9]

    Result

    z=(−32,−12,−12,−12,0,0,1,2)\displaystyle z = \left(- \frac{3}{2}, - \frac{1}{2}, - \frac{1}{2}, - \frac{1}{2}, 0, 0, 1, 2\right)

    ≈ (-1.5, -0.5, -0.5, -0.5, 0, 0, 1, 2)

  3. Given

    x=[1,2,3],δ=1x = [1, 2, 3], \delta = 1

    Result

    z=(−1,0,1)\displaystyle z = \left(-1, 0, 1\right)
  4. Given

    x=[1,2,3,4],δ=1x = [1, 2, 3, 4], \delta = 1

    Result

    z=(−31510,−1510,1510,31510)\displaystyle z = \left(- \frac{3 \sqrt{15}}{10}, - \frac{\sqrt{15}}{10}, \frac{\sqrt{15}}{10}, \frac{3 \sqrt{15}}{10}\right)

    ≈ (-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.