Gradient LabStart the lesson

Lessons › Chapter 5: Generalization

Feature scaling

Lopsided scales turn the error landscape into a long, narrow valley. Gradient descent zigzags across it, wasting steps.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Thousands vs tens

Training is slow and wobbly because income is in the thousands while age is in the tens.

Problem

Features on very different scales

Income is in the tens of thousands; age is in the tens. Drawn to the same scale, age is a flat line next to income. Many models will treat the bigger numbers as more important, just because they are bigger.

Concept

Why it slows training

Lopsided scales turn the error landscape into a long, narrow valley. Gradient descent zigzags across it, wasting steps.

Key idea

Scale them to a common range

feature scaling squeezes every feature into a similar range, such as 0 to 1, or centers it at 0 with a spread of 1. Now income and age stand side by side as equals.

Build

A round bowl, a straight path

With scaled features the valley becomes a round bowl, and gradient descent walks almost straight to the bottom. Same model, much faster training.

Real life

In real life: credit scoring

Credit and insurance models mix money amounts in the thousands with ages, counts of late payments and years at an address. Scaling first means no clue wins just because its numbers happen to be bigger.

Quick check: Why do we scale features?

Scaling puts features on equal footing, so none wins just by having larger numbers, and gradient descent converges faster.

Pseudocode

income = [32000, 54000, 81000]    # huge numbers
age    = [25, 41, 63]             # small numbers

# min-max scaling: squeeze into 0..1
scaled = (x − min) / (max − min)

# or standardize: (x − mean) / std

Key terms

feature scaling
Putting features on similar number ranges, like 0 to 1.

Build it: A screening classifier that doesn’t miss cases (35 min, runs in your browser)

See the project

Build it: Find customer segments with k-means (30 min, runs in your browser)

See the project