Suppose you predict house prices from two features: number of bedrooms (say 1–6) and floor area in square metres (say 30–400). To a distance-based model these live on wildly different scales — a one-bedroom difference is a rounding error next to a 200 m² gap. Left raw, the big-numbered feature drowns out the small one purely because of its units, not its importance. Rescale square metres to square feet and the model's behaviour changes, which should feel alarming: the physics of a house didn't change, only the ruler.
Feature scaling puts every feature on a comparable footing, and feature transformations reshape a feature's distribution so a model can use it well. Both are cheap, both are often decisive, and both hide a subtle leakage trap we will name at the end.
The two workhorses both map a feature onto a standard range, differently:
A rough rule: reach for standardization when the feature is roughly bell-shaped or you're feeding a linear/kernel model, and min-max when you need a hard bounded range (e.g. image pixels, or a neural net input layer). For heavy-tailed data with outliers, a robust scaler (subtract the median, divide by the interquartile range) beats both.
Scaling matters exactly when the model measures distances or takes gradient steps in the raw feature space:
| Model | Needs scaling? | Why |
|---|---|---|
| k-nearest neighbours, k-means | Yes | Euclidean distance is dominated by the largest-scale feature |
| SVM (RBF/linear), regularised regression | Yes | The kernel and the penalty treat all coordinates alike |
| Gradient descent (neural nets, logistic) | Yes | Unequal scales make loss contours elongated → slow, zig-zag convergence |
| Decision trees, random forests, gradient boosting | No | Splits use per-feature thresholds; monotone rescaling changes nothing |
This is why you'll see pipelines standardize before a
Scaling shifts and stretches a feature but keeps its shape. Many real features — income,
population, prices, counts — are heavily right-skewed: a long tail of huge values
drags the mean around and swamps a linear model. A log transform
(
Box-Cox and Yeo-Johnson generalise this: they search a family of
power transforms for the exponent
Picture the loss as a bowl over the weight space. If one feature ranges over thousands and another over units, the bowl is a long, thin valley: the gradient points mostly across the valley, not along it, so the optimiser bounces from wall to wall and inches toward the minimum. Standardizing makes the bowl round, the gradient points straight downhill, and the same learning rate converges in a fraction of the steps. It's the single cheapest speed-up in classical ML.
The mean, standard deviation, min, max, or Box-Cox
Kaggle Learn's Feature
Engineering course has you build log transforms, interaction terms and scaled pipelines on real
data, and shows how scikit-learn's pipeline objects keep scaling from leaking across the
split. Try transforming a skewed price column and watching a linear model improve.