2.1.5 · D1Data Preprocessing & Feature Engineering

Foundations — Min-max scaling and z-score normalization

2,288 words10 min readBack to topic

Before you can read the parent note 2.1.5, you need to own every symbol it throws at you. This page builds each one from nothing, in the order they depend on each other. Nothing here assumes you have seen statistics before.


1. A "feature" and its values — the raw material

  • (no subscript) = "some value from this column", a stand-in for any one number.
  • = "the value in row 3".
  • = the count. If ages = [20, 25, 30, 35, 40], then and .

Figure 1 shows this: every value is a dot dropped onto a horizontal number line. A feature is a cloud of dots on a line — read the dot labels along the axis.

Figure — Min-max scaling and z-score normalization

Why the topic needs it: scaling changes where these dots sit on the line. You cannot describe "moving the dots" until you can name the dots. That is what and are for.


2. Minimum and maximum — the two edges of the cloud

  • For ages [20, 25, 30, 35, 40]: , .

Picture two vertical fence-posts, one at each end of the dot cloud. Everything else lives between them.

Why the topic needs it: min-max scaling works by pinning the left fence-post to and the right fence-post to . To do that you must first find those posts.


3. Range and the difference — the width

  • Ages: range .

Picture the length of the rubber band stretched between the two fence-posts.

Why the topic needs it: to squash a cloud of width down into a cloud of width , you divide by its current width. The range is exactly the number you divide by in min-max scaling. Dividing by a width is how you rescale a length — that is the whole trick.


4. Fractions and "fraction of the way" — what division means here

  • in ages: top , bottom , ratio → halfway.

Figure 2 makes this literal: stand at the left post (value ), walk right until you reach the right post (value ); each dot's label shows what fraction of the walk it sits at, with landing exactly at .

Figure — Min-max scaling and z-score normalization

Why the topic needs it: min-max scaling literally replaces each value by its "fraction of the way" number. Understanding division as "portion of a whole" is the seed of the entire formula.


5. A linear transformation — the reshaping machine

  • If and : result .

Picture zooming the ruler in or out; picks the whole ruler up and moves it left or right. No bending — straight lines stay straight, order is preserved (as long as ).

These two views are the same formula — here's the proof. We demand that the machine send the min to and the max to : The first equation gives . Substitute that into the second: Put back into : Now assemble : So the "fraction of the way" ratio from Section 4 and the " machine" are algebraically identical — two names for one transformation. (Notice is exactly one over the range, so it too blows up when the range is — the same degenerate case as before.)

Why the topic needs it: both scaling methods are secretly just "find the right and ". Min-max solves for the that put min→0, max→1. Z-score solves for the that put the mean→0 and spread→1. Once you see them as the same machine with different targets, the two formulas stop looking like magic.


6. Expectation and the mean — the balance point

  • Scores [60,70,80,90,100]: .
  • is handy because you can write = "the average after transforming", which is how the parent note reasons about scaling.

Picture as the balance point of the dot cloud — the spot where, if the number line were a see-saw with equal weights at each dot, it would tip level.

Why the topic needs it: z-score normalization re-centres the cloud so its balance point sits exactly at . To move a balance point to you subtract from every value. Whenever the parent writes , mentally read it as ", the mean".


7. Variance and standard deviation — the spread

Why square the distances? Because raw distances have plus and minus signs that cancel out (dots left of the mean vs right of it), summing to zero and telling you nothing. Squaring throws away the sign — now every dot contributes a positive "how far out am I" amount. We take the square root at the end to get back to the original units (dollars, not dollars-squared).

Figure 3 contrasts a tight cloud (small ) with a wide one (large ); the arrows mark one measured from the mean line so you can see the "typical step size".

Figure — Min-max scaling and z-score normalization

Why the topic needs it: z-score divides by so that "one unit" of the new scale equals "one typical step" of the old cloud. That is what turns an absolute value into "how many steps from average".


8. The z-score — the finished new coordinate

  • : at the mean. : one step above. : two steps below.

Picture re-labelling the number line so the mean is the new zero and one is the new "1". The dots don't move relative to each other — only the ruler underneath them changes.

Why the topic needs it: is the output of standardization, just as is the output of min-max. Everything above was built so this one line makes complete sense.


Prerequisite map

values x_i, count n

min, max

mean mu

range

fraction 0 to 1

machine a x + b

Min-max

std dev sigma

z-score

Scaling 2.1.5

Both roads (min-max and z-score) start from the same raw dots and pass through the same machine — they just aim at different targets.


Where these feed next


Equipment checklist

Read the question, answer in your head, then reveal.

What do and stand for?
is the value in row of a column; is how many values the column has.
What is the range of a feature and why do we divide by it?
Range , the cloud's width; dividing by it rescales any length into a 0-to-1 fraction.
What goes wrong if (or )?
The formula divides by zero — a constant feature has no spread to scale; detect it and drop the column or output all-zeros.
Solve and for and .
and — giving exactly the min-max ratio.
What does mean, and how does it relate to ?
is the "average of" operator; , the mean.
Why do we square the distances when computing variance, and which divisor is used here?
Squaring removes signs so spread doesn't cancel to zero; we divide by (population variance), not .
What is the difference between and ?
is variance (squared units); is its square root, back in original units — you divide by , never .
What does a z-score of mean in plain words?
The value sits two standard deviations below the mean.