Normalization › Visual Example

Michael BrenndoerferMay 19, 20255 min read
Machine Learning from ScratchAll chapters
Part 3 of 9Foundations
Chapter 26Normalization › Visual Example
Reading section 4 of 10 · Visual Example · 5 minSection 4 of 10 · 5 min

Book contents

Section 4 of 10 · 5 min read

Normalization › 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 normalization maps features with different ranges into a common [0, 1] scale:

Out[2]:
Visualization
Scatter plot comparing age and income features with vastly different scales before normalization.
Original features with vastly different ranges. Age ranges from 20-80 years, while income ranges from 30,000-150,000 dollars. Without normalization, algorithms would be dominated by the income feature due to its larger numeric range.
Scatter plot showing age and income features normalized to same 0-1 scale for fair algorithm treatment.
Normalized features on the same [0, 1] scale. Both features now have minimum 0 and maximum 1. The relative relationships within each feature are preserved, making them comparable.
Original data:
Age - Min: 25 Max: 75
Income - Min: 30000 Max: 130000

Normalized data:
Age - Min: 0.0 Max: 1.0
Income - Min: 0.0 Max: 1.0

Example: Step-by-Step Calculation

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

  • x1: age in years → [25, 35, 45, 55, 65, 75]
  • x2: income in thousands → [30, 50, 70, 90, 110, 130]

Step 1: Calculate min and max values

  • min⁡(x1)=25\min(x_1) = 25, max⁡(x1)=75\max(x_1) = 75
  • min⁡(x2)=30\min(x_2) = 30, max⁡(x2)=130\max(x_2) = 130

Step 2: Apply normalization formula

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

  • x11′=25−2575−25=050=0.000x'_{11} = \frac{25 - 25}{75 - 25} = \frac{0}{50} = 0.000
  • x21′=35−2575−25=1050=0.200x'_{21} = \frac{35 - 25}{75 - 25} = \frac{10}{50} = 0.200
  • x31′=45−2575−25=2050=0.400x'_{31} = \frac{45 - 25}{75 - 25} = \frac{20}{50} = 0.400
  • x41′=55−2575−25=3050=0.600x'_{41} = \frac{55 - 25}{75 - 25} = \frac{30}{50} = 0.600
  • x51′=65−2575−25=4050=0.800x'_{51} = \frac{65 - 25}{75 - 25} = \frac{40}{50} = 0.800
  • x61′=75−2575−25=5050=1.000x'_{61} = \frac{75 - 25}{75 - 25} = \frac{50}{50} = 1.000

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

  • x12′=30−30130−30=0100=0.000x'_{12} = \frac{30 - 30}{130 - 30} = \frac{0}{100} = 0.000
  • x22′=50−30130−30=20100=0.200x'_{22} = \frac{50 - 30}{130 - 30} = \frac{20}{100} = 0.200
  • x32′=70−30130−30=40100=0.400x'_{32} = \frac{70 - 30}{130 - 30} = \frac{40}{100} = 0.400
  • x42′=90−30130−30=60100=0.600x'_{42} = \frac{90 - 30}{130 - 30} = \frac{60}{100} = 0.600
  • x52′=110−30130−30=80100=0.800x'_{52} = \frac{110 - 30}{130 - 30} = \frac{80}{100} = 0.800
  • x62′=130−30130−30=100100=1.000x'_{62} = \frac{130 - 30}{130 - 30} = \frac{100}{100} = 1.000

Result: Both features are now on the same [0, 1] scale:

  • x1: [25, 35, 45, 55, 65, 75] → [0.000, 0.200, 0.400, 0.600, 0.800, 1.000]
  • x2: [30, 50, 70, 90, 110, 130] → [0.000, 0.200, 0.400, 0.600, 0.800, 1.000]