Feature Scaling: 3 Essential Methods Made Simple

⚡ TL;DR: Feature scaling puts your columns on a comparable numeric range. Use standardisation (z-score) by default, normalisation (min–max) when you need bounded values, and robust scaling when outliers matter. Always fit the scaler on training data only.

Feature scaling is one of those steps that seems like fussy housekeeping until it silently ruins a model. This page explains what it is, the three main methods, and — the part usually left out — how to decide which to use and when you can skip it.

Why feature scaling matters

Suppose you are predicting house prices from two features: number of bedrooms (range 1 to 5) and floor area in cm² (range 400,000 to 2,000,000). Both are useful. But numerically one is hundreds of thousands of times larger, and several algorithms take that literally.

Feature scaling before and after standardisation, showing bedroom counts collapsing onto a line on a shared scale then spreading out evenly
Without feature scaling, plotted on one shared scale, the bedroom count vanishes entirely. After standardisation both features carry equal weight.

Anything that measures distance between rows — k-nearest neighbours, k-means, anything using cosine similarity — finds that floor area dominates the arithmetic completely. Two houses differing by 3 bedrooms differ by 3 in that dimension; two differing by one square metre differ by 10,000. Bedrooms are ignored, not because they are unimportant but because their units are small.

Gradient descent suffers differently. With features on very different scales the loss surface becomes a long narrow valley rather than a round bowl, so gradient descent zigzags across the steep direction while creeping along the shallow one — converging slowly, or diverging entirely unless the learning rate is tiny.

Method 1 — normalisation (min–max feature scaling)

Squash every feature into a fixed range, usually 0 to 1:

$$x’ = \frac{x – x_{\min}}{x_{\max} – x_{\min}}$$

The smallest value becomes 0, the largest becomes 1. With bedrooms ranging 1 to 5, a 3-bedroom house becomes (3 − 1) ÷ (5 − 1) = 0.5.

⚠️ Outliers break min–max scaling

One mansion of 10,000 m² in a dataset of normal houses drags the maximum so far up that every ordinary house compresses into the bottom sliver of the range — destroying the distinction between them.

Method 2 — standardisation (z-score feature scaling)

Recentre each feature to a mean of 0 and a standard deviation of 1:

$$x’ = \frac{x – \mu}{\sigma}$$

A value of 0 now means “average”; +1 means “one standard deviation above average”. Values are not bounded, so genuine outliers stay far out — often exactly what you want. This is the same z-score from statistics.

✅ Standardisation is the sensible default. If you are unsure which feature scaling method to use, use this one. It suits linear and logistic regression, PCA and support vector machines, and it does not assume your data is bounded.

Method 3 — robust scaling

If your data has serious outliers you do not want to remove, subtract the median and divide by the interquartile range. Because the median and IQR barely move when you add extreme values, the scaling stays sensible.

MethodOutput rangeOutliersTypical use
NormalisationBounded, 0 to 1Poor — they compress everything elseImage pixels, bounded neural net inputs
StandardisationUnbounded, centred on 0Good — they stay distinguishableMost classical ML: regression, SVM, PCA
RobustUnbounded, centred on medianBest — barely affectedData with heavy outliers

Which algorithms need feature scaling

Scaling required
k-nearest neighbours · k-means · SVM · neural networks · PCA · anything trained by gradient descent · regularised linear or logistic regression
Scaling not needed
Decision trees · random forests · gradient boosting — they split on thresholds, which rescaling does not change

If you are using a random forest, you can skip feature scaling entirely. PCA is the case people forget: it maximises variance, so unscaled large-range features dominate every component — see step-by-step PCA with NumPy.

The feature scaling mistake that inflates your results

This matters more than the choice of method. Fit the scaler on the training set only.

The wrong order — scale the whole dataset, then split — means the mean and standard deviation were computed using test rows. Information has leaked into training and your evaluation is no longer honest. The effect is usually small, but it is exactly the invisible optimism that makes a model look better in development than in production.

🧪 The correct order, every time

  1. Split into training and test sets.
  2. Compute the mean and standard deviation from the training set only.
  3. Apply those numbers to transform the training set.
  4. Apply those same numbers again to the test set — never recompute them.
In scikit-learn this is the difference between fit_transform on training data and transform alone on test data. The asymmetry is deliberate.

The same rule applies in production: save the training mean and standard deviation alongside the model, because every future prediction must be scaled with identical numbers.

Two smaller traps

  • Scaling the target. Usually unnecessary — and if you do it, you must reverse the transformation on predictions, or your model will confidently report that a house costs 0.34.
  • Scaling one-hot encoded columns. A column that is already 0 or 1 does not need feature scaling. Standardising it produces odd values and makes coefficients harder to interpret, for no benefit.

🔑 Key Takeaways

  • Feature scaling matters whenever an algorithm measures distance or is trained by gradient descent.
  • Standardisation is the default; normalisation for bounded ranges; robust scaling when outliers dominate.
  • Tree-based models need no scaling at all.
  • Fit the scaler on training data only, then apply the same numbers to test data and to production.
  • Do not scale one-hot columns, and reverse any scaling applied to the target.

Further reading

scikit-learn’s preprocessing guide documents every scaler mentioned here, and its comparison of scalers on real data shows visually how each behaves when outliers are present.

Where to go next

Scroll to Top