Standardization › Visual Example

Michael BrenndoerferApril 25, 20254 min read
Machine Learning from ScratchAll chapters
Part 3 of 9Foundations
Chapter 25Standardization › Visual Example
Reading section 4 of 10 · Visual Example · 4 minSection 4 of 10 · 4 min

Book contents

Section 4 of 10 · 4 min read

Standardization › Visual ExampleOne section · Sections in this chapter4 / 10 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

This example demonstrates how standardization maps features with different scales into a common scale:

Out[2]:
Visualization
Scatter plot of six houses, labeled with their house size and bedroom count, showing that the original features use very different numeric scales.
Original features with vastly different scales. House size ranges from 1000-2000 square feet, while number of bedrooms ranges from 2-4. Without standardization, algorithms would be dominated by the house size feature due to its larger numeric values.
Scatter plot of the same six houses labeled with their standardized coordinates, showing both features centered near zero on the same scale.
Standardized features on the same scale. Both features now have mean 0 and standard deviation 1. The relative relationships within each feature are preserved, making them directly comparable.
Original data:
House Size - Mean: 1516.67 Std: 338.71
Bedrooms - Mean: 3.0 Std: 0.82

Standardized data:
House Size - Mean: -0.0 Std: 1.0
Bedrooms - Mean: 0.0 Std: 1.0

Example: Step-by-Step Calculation

Let's work through a detailed example with two features:

  • x1: house size in square feet → [1000, 1500, 2000]
  • x2: number of bedrooms → [2, 3, 4]

Step 1: Calculate means

  • xˉ1=(1000+1500+2000)/3=1500\bar{x}_1 = (1000 + 1500 + 2000)/3 = 1500
  • xˉ2=(2+3+4)/3=3\bar{x}_2 = (2 + 3 + 4)/3 = 3

Step 2: Calculate standard deviations

  • s1=((1000−1500)2+(1500−1500)2+(2000−1500)2)/3=(250000+0+250000)/3≈408.25s_1 = \sqrt{((1000-1500)^2 + (1500-1500)^2 + (2000-1500)^2)/3} = \sqrt{(250000 + 0 + 250000)/3} \approx 408.25
  • s2=((2−3)2+(3−3)2+(4−3)2)/3=(1+0+1)/3≈0.82s_2 = \sqrt{((2-3)^2 + (3-3)^2 + (4-3)^2)/3} = \sqrt{(1 + 0 + 1)/3} \approx 0.82

Step 3: Apply standardization formula

For the first feature (j=1j=1):

  • z11=1000−1500408.25≈−1.225z_{11} = \frac{1000 - 1500}{408.25} \approx -1.225
  • z21=1500−1500408.25=0.000z_{21} = \frac{1500 - 1500}{408.25} = 0.000
  • z31=2000−1500408.25≈1.225z_{31} = \frac{2000 - 1500}{408.25} \approx 1.225

For the second feature (j=2j=2):

  • z12=2−30.82≈−1.225z_{12} = \frac{2 - 3}{0.82} \approx -1.225
  • z22=3−30.82=0.000z_{22} = \frac{3 - 3}{0.82} = 0.000
  • z32=4−30.82≈1.225z_{32} = \frac{4 - 3}{0.82} \approx 1.225

Result: Both features are now on the same scale:

  • x1: [1000, 1500, 2000] → [-1.225, 0.000, 1.225]
  • x2: [2, 3, 4] → [-1.225, 0.000, 1.225]