2.1.4 · D2Data Preprocessing & Feature Engineering

Visual walkthrough — Feature scaling - normalization vs standardization

2,022 words9 min readBack to topic

This page builds both scaling formulas from absolute zero. We assume you know nothing except that numbers can sit on a number line and that we can stretch and slide them. Every symbol is earned before it is used. This is the visual companion to the parent note.

We will discover that there are exactly two natural ways to "slide and stretch", and each answers a different question.


Step 1 — What is a feature, drawn as dots on a line

WHAT. Take one column of raw data, for example five incomes: Each number is one dot on a horizontal number line.

WHY. Before we transform anything, we must see the raw object. Every operation later is just moving these dots. If you can picture the dots, you can picture the math.

PICTURE. Look at the figure. The dots are bunched near the left; the lone red dot at sits far away. That red dot is the villain of this whole story — remember it.

Figure — Feature scaling -  normalization vs standardization

Step 2 — The only move we allow: slide then stretch

WHAT. We restrict ourselves to a linear transformation: Here multiplies every dot (stretch or shrink the spacing) and adds to every dot (slide the whole line left or right).

WHY this and not something fancier? Because a linear move is the only kind that never reorders the dots and never distorts their relative spacing. If house A was cheaper than house B, it must stay cheaper, and by a proportional amount. Any curved (nonlinear) transform would secretly change which points are "close", corrupting distance-based algorithms. So we demand: slide () and stretch (), nothing else.

PICTURE. The figure shows the same dots twice: top row is the original, bottom row is after one (stretch) and one (slide). The pattern of gaps is identical — only the ruler underneath changed.

Figure — Feature scaling -  normalization vs standardization

Step 3 — Wish A: "land the ends on 0 and 1" → Normalization

WHAT. Our two conditions are: the smallest value should map to , and the largest value should map to .

Condition 1 — plug in , demand output :

Condition 2 — plug in , demand output :

WHY these two wishes? Because "fit inside a box from 0 to 1" is exactly what bounded algorithms want — pixel intensities, probabilities, or sigmoid inputs in neural networks all live in a fixed box.

PICTURE. The figure shows a rubber band pinned at (which must land on ) and at (which must land on ). Everything in between is dragged proportionally.

Figure — Feature scaling -  normalization vs standardization

Substituting and back into the template gives the famous result:

Check the villain-free example, prices (thousands): width , so , . The percentages () survive untouched.


Step 4 — Why one outlier destroys Normalization

WHAT. Feed in the villain: . Now , , width .

WHY it fails. The width is set by the single extreme value. The four honest points get crushed into the tiny interval — they become nearly indistinguishable. Any algorithm now "sees" four identical points and one loner.

PICTURE. The figure shows the four good dots squeezed against the left wall while the red outlier hogs the entire ruler. This is why Normalization demands no outliers — see outlier handling.

Figure — Feature scaling -  normalization vs standardization

Step 5 — Wish B: "center at 0, spread of 1" → Standardization

WHAT. Same template , but now two statistical wishes. First we need the mean and standard deviation. Throughout, let = the number of observations (here ), and let be the -th value.

We now introduce two shorthand words for "what happens on average" — because our two wishes are about the average value and the average spread of the transformed dots.

Condition 1 — make the new mean . Using :

Condition 2 — make the new spread , i.e. variance . Using :

WHY these wishes? "Distance from typical, measured in spreads" is dimensionless and outlier-tolerant — perfect for regularization, PCA, and gradient descent.

PICTURE. The figure marks as the pivot; subtracting slides the pivot to , dividing by rescales the ruler so one standard deviation equals one tick.

Figure — Feature scaling -  normalization vs standardization

Step 6 — Why Standardization survives the outlier

WHAT. Feed in the same villain . First the mean: Now the (population) standard deviation. The squared distances from are: Then each z-score :

WHY it survives. The denominator is , an average spread — a single huge value inflates it only mildly, not to the full width. So the four honest points keep visible gaps ( vs …), while the outlier is flagged at rather than allowed to crush everyone.

PICTURE. The figure shows the same red villain as Step 4, but now the four good dots stay clearly separated. Compare this figure directly with Step 4 — same data, opposite outcome.

Figure — Feature scaling -  normalization vs standardization

Step 7 — The degenerate case: all values identical

WHAT. What if every value is the same, e.g. ?

WHY it matters. Then , so Normalization's denominator is ; and , so Standardization's denominator is . Division by zero — both formulas explode.

PICTURE. The figure shows a single stacked dot: there is no spread to normalize. The lesson: a constant feature carries no information and cannot be scaled — drop it.

Figure — Feature scaling -  normalization vs standardization

The one-picture summary

Both methods are the same linear move ; they differ only in which two wishes fix and . Normalization pins the ends to a box; Standardization pins the center and spread to the standard bell. The figure lays the raw dots, the normalized dots, and the standardized dots on three parallel rulers so you can watch the villain outlier shrink under standardization but dominate under normalization.

Figure — Feature scaling -  normalization vs standardization
Recall Feynman retelling — say it back in plain words

We started with a bunch of dots on a line. We promised to only slide and stretch them, because that keeps their order and spacing honest. That promise is a formula with two knobs: (stretch) and (slide). Two knobs need two wishes to lock them down.

Wish A: "smallest dot lands on 0, largest lands on 1." Solving gives Normalization — every dot becomes its percentage of the way across the range. Neat, but the biggest value sets the ruler, so one freak value squashes everyone.

Wish B: "the pile balances at 0 and has a typical spread of 1." Solving gives Standardization — every dot becomes how many standard deviations from typical. Because spread is an average, one freak value only nudges the ruler, so honest points stay separated and the freak gets flagged, not obeyed. Standardization is more outlier-tolerant, but not immune — an extreme value still tugs on and a little.

Edge case: if all dots sit on the same spot there's nothing to stretch (divide-by-zero), so we just throw that column away.

Recall Two quick self-checks

Which method would you use for pixel values known to lie in ? ::: Normalization — the range is bounded and outlier-free, and we often want a fixed box. A house-price column has one mansion among homes. Which method keeps the ordinary houses distinguishable? ::: Standardization — the mansion becomes a large z-score but the average spread barely moves.