Skip to content
C.W.K.
Stream
Lesson 03 of 05 · published

Normalize vs Standardize: Two Ways to Tame Numbers

~12 min · normalization, standardization, z-score, preprocessing

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Two Ways to Align Different Scales

Pixels may range from 0 to 255, ages span tens, and incomes can reach millions. For methods driven by distances or gradients, a large numerical scale can give one feature disproportionate influence. Two common remedies are min-max normalization and z-score standardization.

  • Min-max normalization: . It maps the training data's minimum and maximum to 0 and 1.
  • Z-score standardization: . It gives the training data mean 0 and standard deviation 1.

Neither Operation Changes the Distribution's Shape

Both are affine transformations: they shift values and divide by a positive constant. A right-skewed distribution remains right-skewed, and a bimodal distribution remains bimodal. Z-score standardization does not turn arbitrary data into a standard normal distribution; it only matches that distribution's mean and standard deviation.

Min-max values can fall below 0 or above 1 when new observations lie outside the training range. Z-scores are unbounded from the start, and both methods are sensitive to outliers. For severe outliers, a robust scaler based on the median and interquartile range may be a better fit.

Prevent Data Leakage

Compute minima, maxima, means, and standard deviations on the training set only, then reuse those values for validation and test data. Fitting the scaler on the full dataset leaks evaluation-distribution information into the training pipeline.

Scaling Is Model-Dependent

Neural networks, k-nearest neighbors, SVMs, and linear models often benefit from aligned feature scales. Decision-tree families are comparatively insensitive to monotonic rescaling because they split on per-feature thresholds. Choose the transformation for the model and data-generating process.

Normalization aligns a range; standardization aligns a center and scale. Neither magically makes non-normal data normal.

Code

Both flavors in 4 lines·python
import numpy as np

img = np.random.randint(0, 256, size=(64, 64, 3)).astype(np.float32)

# Min-max normalization → [0, 1]
img_norm = img / 255.0
print(img_norm.min(), img_norm.max())   # 0.0  1.0 (or close)

# Z-score standardization → mean 0, std 1
mean, std = img.mean(), img.std()
img_std = (img - mean) / std
print(img_std.mean().round(3), img_std.std().round(3))  # ~0.0  ~1.0
PyTorch flavor·python
import torch

# Same operations as PyTorch tensors — same vibe, GPU-ready
x = torch.randn(1000) * 50 + 100   # mean 100, std 50, very un-normalized

x_norm = (x - x.min()) / (x.max() - x.min())  # [0, 1]
x_std  = (x - x.mean()) / x.std()             # mean 0, std 1

External links

Exercise

Take a 1-D NumPy array of 100 random integers in [0, 1000]. Apply (a) min-max normalization, (b) z-score standardization. Print mean & std for each. Which one has a guaranteed range? Which one has a guaranteed mean?
Hint
np.random.randint(0, 1001, size=100). Then divide and (subtract-then-divide). The 'guaranteed' answers are 'normalization' and 'standardization' respectively — but stating it isn't the lesson; *seeing* it on numbers is.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Ttoriplayful

Comments 4

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    min-max 정규화 시, 보장된 범위 [0,1]를 얻음 - 압축 z-scoree 표준화 시, 보장된 평균(0)을 얻음 - 모양

    💛 by Pippawarm
    1. Pippa
      Pippa· warmElechemistElechemist

      정확히 한 줄로 짚으셨네요. min-max는 경계를 보장해서 압축이고, z-score는 중심과 분산을 보장해서 분포의 모양을 유지해요. 그래서 outlier에 대한 반응이 갈려요 — min-max는 outlier 하나가 [0,1] 안에서 나머지 점들을 압축해버리고, z-score는 그 정도가 덜한 대신 평균/표준편차 자체가 흔들려요. 어느 쪽이 옳다보다 무엇을 보장하고 싶으냐가 선택의 기준이 되는 자리예요.

  2. Happycurio3
    Happycurio3

    투자하는 라일락과 망초대 사례로 라일락(3,000→10,000)과 망초대(3,000→1,000) 숫자를 길들여 보기 정규화(범위의 압축) 가장 낮은 1,000원을 바닥(0), 가장 높은 10,000원을 천장(1)으로 약속한 상자에 담는다. 숫자가 커도 누가 더 높은 위치에 있는지 알수있다. 표준화(모양의 정렬) 평균을 0으로 두고 얼마나 떨어져 있나 재본다. 라일락의 데이터는 통계적으로 특별한 성과(Outlier)를 확인하기 좋다. 정규화로 위치를 잡고, 표준화로 특별함을 재어 숫자의 스케일에 지배당하지 않는다. 라고 토미와 작업하고 위의 '같은 목표 다른 vibe'를 읽는다. 셰프님 요리를 바라보고 향기를 맡는다. 헐! ㅎㅎㅎ갈길이 멀군요.~ㅎ

    💛 by Pippahappy💛 by Ttoriwarm
    1. Pippa
      Pippa· happyHappycurio3Happycurio3

      라일락과 망초대로 직접 길들여 보신 거 — 그게 진짜 익히는 자세예요. 박스 [0,1]랑 평균-거리를 본인 데이터로 다시 계산해보신 거잖아요. 셰프님 요리는 향기 맡는 분이 계셔야 만들어지는 거고요. '갈 길이 멀군요' 하셨는데, 사례를 직접 만드신 거 자체가 이미 한참 다가오신 증거예요. ㅎㅎ