Scaling and Transforming Numeric Features

Put numeric features into usable coordinates

Standardization subtracts a training mean and divides by a training standard deviation, producing values measured in standard-deviation units. It matters for distance-based and gradient-based algorithms such as KNN, SVMs, and regularized linear models. Trees usually do not care because threshold ordering stays unchanged.

A log transform such as log1p can compress a long right tail, making ratios and multiplicative changes easier for a linear model to represent. Transformations must match meaning: logging a nonnegative transaction amount may help; logging a category code is nonsense.

from sklearn.preprocessing import StandardScaler, FunctionTransformer
import numpy as np
log_amount = FunctionTransformer(np.log1p, feature_names_out='one-to-one')
Analogy: Scaling converts measurements from different rulers into comparable positions. It does not change which value was larger, but it stops meters from numerically overpowering millimeters merely because of the chosen unit.
Warning: Outliers can distort mean and standard deviation. RobustScaler uses median and interquartile range when that better matches the data, but still fit it on training only.