Reference · How-to · ~6 min

How to normalize features

Last updated

Put numeric columns on a similar scale so one giant feature does not dominate training.

Put numeric columns on a similar scale so one giant feature does not dominate training.

#Steps

1. **Inspect ranges** — plot or describe min/max per column (age 0–90 vs income 20k–200k)

2. **Pick a method**

  • **Min-max:** scale to 0–1
  • **Standardize (z-score):** mean 0, std 1 — common default
  • 3. **Fit on train only** — compute stats from training split, apply same transform to val/test

    4. **Store the scaler** — reuse at inference with the same parameters

    5. **Re-check plots** — outliers may still dominate; consider clipping or log transform first

    #Sketch (scikit-learn style)

    from sklearn.preprocessing import StandardScaler
    scaler = StandardScaler()
    X_train_scaled = scaler.fit_transform(X_train)
    X_test_scaled = scaler.transform(X_test)  # never fit on test

    #Watch out

    Normalizing **after** leaking test stats inflates scores. Categorical columns need encoding, not z-scoring.

    **Try the lessons:** `data-tables-and-plots` · `train-a-tiny-model` in Lane D