Worked examples — Min-max scaling and z-score normalization
The parent note Min-max scaling and z-score normalization gave you two formulas:
Formulas are easy to read. The trap is all the little cases where the plain formula surprises you: what if every value is the same? what if a value is negative? what if a new test point falls outside the training range? This page marches through every one of those cases with a fully worked example, so you never meet a scenario you haven't already seen.
Before we compute anything, let us re-earn the two ingredients we lean on the most.
Here (capital sigma, "sum") means "add up the thing on its right for every value". The letter under it is just a counter — it starts at and steps up to (the count of values), so means "the -th value in the list": , then , and so on until . We use the square root at the end for one reason: the variance is in squared units (squared dollars, squared years — meaningless to picture), and the root brings us back to real, plottable units.
The scenario matrix
Every scaling question you will ever be asked lands in one of these cells. The gallery below hits all of them.
| # | Case class | What makes it tricky | Covered by |
|---|---|---|---|
| A | Plain positive spread | baseline — nothing weird | Example 1 |
| B | Negative & positive mixed values | signs must survive scaling | Example 2 |
| C | Degenerate: all values equal | denominator becomes | Example 3 |
| D | Custom target range | two knobs (stretch + shift) | Example 4 |
| E | Outlier present | min-max collapses; z-score resists | Example 5 |
| F | New test point outside train range | output escapes (above max AND below min) | Example 6 |
| G | Real-world word problem (two features, distance) | why we scale at all | Example 7 |
| H | Exam twist: recover original from scaled | invert the formula | Example 8 |
Keep this table beside you; each example names its cell. The figure below shows the single most important picture on this page: what min-max does to a line of data.

Read the figure top to bottom. The lavender line at the top holds the five raw heights sitting on a real number line. The coral arrows carry each dot straight down to its new home on the mint line below, and the numbers underneath () are the scaled values. Notice the spacing is preserved — the dots are still evenly spread; min-max only slid the smallest dot to and shrank the largest to . That "shift then squash" is the whole formula, drawn once so you can picture it in every example that follows.
Example 1 — Cell A: the plain baseline
Forecast: before reading on, guess where lands. It's the middle of five evenly spaced values — pencil in your guess.
- Find the pegs. , , so the range is . Why this step? The formula needs both end pegs; the range is the denominator that squashes everything into a length-1 interval.
- Shift then squash each value with :
- Why this step? Subtracting the min slides the whole line so the smallest value sits at ; dividing by the range shrinks the far peg to exactly . This is exactly the coral-arrow mapping drawn in the figure above.
Result: . Your forecast for should have been .
Recall Verify
Smallest input maps to 0? ::: Yes, . Largest input maps to 1? ::: Yes, .
Example 2 — Cell B: negative and positive values together
Forecast: does °C map to in scaled units? Guess yes/no.
- Pegs: , , range . Why this step? The range is always max minus min; here that subtraction turns two minus signs into a positive . If you ever get a negative range you swapped min and max.
- Apply :
- Why this step? The centre value °C is the midpoint of the data, and min-max always sends the midpoint to — the raw sign of the value is irrelevant.
Result: . So the answer to the forecast is no — raw maps to scaled , because "zero temperature" has no special meaning to the scaler; only position between the pegs matters.
Example 3 — Cell C: the degenerate all-equal list
Forecast: predict what breaks.
- Min-max pegs: , , range . Why this step? Notice the denominator is . — undefined. The formula has no answer.
- Z-score: , and every , so . Then — also undefined. Why this step? A feature with zero spread carries no information — every row is the same. Neither method can rank values that don't differ.
Result: both formulas divide by zero.
Recall Verify
Range of an all-equal list? ::: , which makes both scalers divide by zero.
Example 4 — Cell D: custom target range
Formula reminder (from the parent's generalized version):
Forecast: the smallest value must land on and the largest on — guess where falls.
- Pegs: , , range , and . Why this step? is the width of the new window; we first make a number, then stretch it by that width and shift it to start at .
- Apply :
Result: .
Verify (units & endpoints): the two end pegs hit and exactly, and everything else lies between — the window is filled correctly.
Example 5 — Cell E: an outlier, min-max vs z-score
Forecast: which method keeps the four "normal" salaries readable — spread out — and which squashes them into a tiny corner?
Min-max path
- Pegs: , , range .
- . Why this step? The outlier at blew the range up to , so the four ordinary salaries all get crammed into — they become nearly indistinguishable.
Z-score path
- Mean: . Why this step? We must fit first because it is the anchor point every deviation is measured from — you cannot know "how far below/above average" a value is until you know where average sits. is the seesaw balance point the whole z-score is built around.
- Squared deviations (each value minus , then squared):
- Why this step? We square each deviation so that a value below the mean (negative gap) and one above (positive gap) both count as pure distance — the sign is erased and only "how far" survives, which is exactly what spread should measure.
- Add them up, then average by dividing by : Why this step? Averaging the squared distances is the definition of variance; showing the running sum keeps the arithmetic honest instead of asking you to trust a jump.
- Root to get the standard deviation: .
- , and . Why this step? Standard deviation measures typical spread, not the extreme end pegs, so one outlier moves it far less than it moves the max.
Result: z-score keeps the normal salaries near (readable) and flags the outlier as standard deviations out — a clear signal, not a crushing one.
The picture below puts both methods side by side on the same data.

On the left (coral) the four normal salaries all collapse into the yellow band near — min-max let the outlier hog the whole scale. On the right (lavender) the same four salaries stay comfortably spread around the mint dashed mean line, while the outlier sits alone near . Same numbers, two completely different stories: that visual gap is exactly why you reach for z-score when extremes are present.
Example 6 — Cell F: test points outside the training range (both sides)
Forecast: will the first stay above ? will the second go below ? guess both.
- Use the training pegs — never refit. Why this step? The model learned its decision boundaries in the training coordinate system; a test point must be placed in that same system to be comparable.
- Above the max — age 50: . Why this step? lies beyond the training max, so the numerator exceeds the denominator and the result overshoots .
- Below the min — age 15: . Why this step? is smaller than the training min, so the numerator goes negative and the result dips below — the mirror image of the overshoot above.
Result: age (above ) and age (below ). Both escaping the box is correct behaviour — min-max is not clamped, and a value on either side of the training pegs legitimately reads outside on the matching side.
Recall Verify
Scaled value of age 50 with train pegs [20,40]? ::: , correctly above . Scaled value of age 15 with train pegs [20,40]? ::: , correctly below .
Example 7 — Cell G: the real-world "why we scale" problem
Forecast: intuitively the query has the same area as P but the same bedrooms as Q. Which one wins depends entirely on scaling — guess before computing.
The distance we use is the straight-line (Euclidean) distance The and squares just generalize the ruler distance to two axes at once.
- Unscaled distances.
- Query→P: .
- Query→Q: . Why this step? Area differences are measured in thousands, bedroom differences in single digits, so area's raw scale dominates the square. Here P wins () — but only because area's units, not its importance, are bigger.
- Min-max scale both features first, using the min and max of the two known houses P and Q. Area over is (range ); beds over is (range ). Scaling each coordinate difference by its own feature's range:
- Query→P scaled: area diff , beds diff → .
- Query→Q scaled: area diff , beds diff → . Why this step? We divide each feature by its own range so that a full-range change in area counts exactly as much as a full-range change in bedrooms — that equalizes the two features' influence and stops the wide-unit feature (area) from silently drowning out the narrow-unit one (bedrooms).
Result: unscaled, area silently dominated and P was "closer" (); scaled, area and bedrooms get equal say and the two neighbours become a genuine tie (). Scaling flipped the model's answer from "P is nearest" to "P and Q are equally near" — this is the concrete reason distance-based methods need scaling at all.
Verify (sanity): after min-max the biggest possible single-feature gap is (min→max), so no scaled coordinate difference can exceed in size — both distances landing at exactly is consistent with that bound.
Example 8 — Cell H: the exam twist (invert the formula)
Forecast: it should sit of the way from to — estimate it.
- Write the forward formula and solve for . From , multiply both sides by the range and add back the min: Why this step? Min-max is a straight-line (invertible) map — undo it by reversing the two operations in reverse order: first un-squash (multiply by range), then un-shift (add min).
- Plug in: . Why this step? Substituting the stored scaled number and the training pegs walks the transformation backwards to the single raw value that produced it.
Result: the original value was .
Verify (forward check): ✓ — feeding back through the forward formula returns the stored .
Bringing it together
The flowchart below is a decision map: follow the arrows top to bottom to pick a scaler.
Walk it in words. Start at the top box, "numeric feature" — this whole map only applies to numbers, not to label columns from encoding. The first diamond asks "are outliers present?" If yes, take the right branch straight to z-score (or robust) scaling, because Example 5 showed min-max collapses under extremes. If no, the second diamond asks "do you need a bounded output?" — say, for a neural network expecting inputs in a box. If yes, choose min-max; if no, z-score is the safe default. Both branches then funnel into the same two final boxes: fit the scaler on the training set only, then transform train and test with those same numbers — the exact rule Example 6 protected.
Recall Self-test
Which cell has a zero denominator? ::: Cell C, an all-equal (constant) feature. Why can a min-max test value exceed 1 or drop below 0? ::: Because we keep the training min/max; a new point beyond the max overshoots and one below the min dips under (Cell F). Which method is less disturbed by an outlier and why? ::: Z-score, because measures typical spread, not the extreme end pegs.
Connections: these same scaling ideas feed PCA, batch normalization, and the input pipeline for feature selection; label/one-hot columns from encoding are usually left unscaled. Prefer the Hinglish walkthrough? See 2.1.05 Min-max scaling and z-score normalization (Hinglish).