What common scalers do
- Standard scaling subtracts a feature's training mean and divides by its standard deviation. The transformed feature has mean 0 and standard deviation 1 on that training data.
- Min–max scaling maps the training minimum and maximum to chosen endpoints, commonly 0 and 1. It is useful when a bounded range is required, but a new extreme value can compress most observations into a narrow interval.
- Robust scaling uses the median and interquartile range. It is less sensitive to extreme values than mean-and-standard-deviation scaling, though it does not make outliers harmless.
For example, if age has mean 40 and standard deviation 10, age 30 becomes −1. If income has mean £45,000 and standard deviation £15,000, £30,000 also becomes −1. The two values now represent the same distance from their respective training means.
Which models benefit
Scaling usually matters for methods that compare distances or use coefficient magnitudes, including KNN, K-means, PCA, RBF-kernel SVMs, and regularised linear models. Neural-network optimisation can also be easier when inputs have comparable ranges.
Decision trees and tree ensembles usually do not need feature scaling: a split such as income ≤ 45000 can be expressed as an equivalent threshold after a monotonic rescaling. Scaling may still be useful for a shared preprocessing pipeline, but it generally does not change those tree splits.
Fit preprocessing on training data only
Learn the scaler's statistics from the training split, then use that fitted scaler to transform validation and test rows. If you calculate the mean, standard deviation, minimum, or maximum from the whole dataset first, information from the held-out rows has entered training. That is data leakage. A pipeline keeps the scaler inside each training fold during cross-validation.
Common mistakes with Feature Scaling
- Assuming standard scaling removes outlier influence. Mean and standard deviation can both be pulled by extreme values; consider robust scaling when that is appropriate.
- Fitting a new scaler on validation or test data. Reuse the scaler fitted on training data so evaluation matches deployment.
- Scaling without a reason. Tree-based models generally do not need it. Binary indicator columns are often kept as 0/1 so their meaning remains clear.
- Forgetting to invert target transformations. If the target was scaled, convert predictions back to the original units before interpreting errors or reporting results.