Why do linear and distance-based models require feature scaling while decision trees do not?
Last updated
Linear and distance-based models combine features arithmetically (weighted sums, distances, dot products), so a feature's units directly change its influence. Trees only ask threshold questions about one feature at a time, and any monotonic rescaling preserves the ordering those thresholds depend on.
Distance-based models (k-NN, k-means, RBF-kernel SVM):
Euclidean distance sums squared differences, so a feature in the range 0 to 100,000 (income) swamps one in the range 0 to 1 (a ratio).
Unscaled data effectively assigns arbitrary feature weights based on units.
Linear models trained by gradient descent:
Mismatched scales make the loss surface elongated (ill-conditioned), so a single learning rate is too big for some directions and too small for others. Convergence is slow or oscillates.
Unregularized OLS predictions are scale-invariant (coefficients just rescale), but optimization still suffers.
Regularized linear models (Ridge, Lasso, regularized logistic regression): The penalty on
||w||treats all coefficients equally, but a feature with small units needs a large coefficient, so it gets penalized more. Scaling makes the penalty fair.Trees are invariant to monotonic transforms:
A split
x_j <= tpartitions samples by rank order. Scalingx_jjust movestand yields the identical partition.Features are never combined across a single split, so relative magnitudes between features don't matter. This holds for random forests and gradient-boosted trees as well.
Practical note: fit the scaler (e.g.
StandardScaler) on training data only, inside aPipeline, to avoid leakage.
- https://www.geeksforgeeks.org/machine-learning/does-linear-regression-require-feature-scaling/
- https://medium.com/@post.gourang/feature-scaling-in-machine-learning-which-popular-algorithms-require-it-and-which-dont-a71f5585d664
- https://www.geeksforgeeks.org/machine-learning/pros-and-cons-of-decision-tree-regression-in-machine-learning/