Scaling and constant columns
Quick answer
Scaling changes feature units to make values more comparable for methods that depend on distances, penalties or gradient steps. Standardization subtracts the training mean and divides by the training standard deviation. A constant training feature needs an explicit zero-variance policy; scikit-learn StandardScaler uses a scale factor of one for zero variance. All examples use synthetic inputs and local scikit-learn 1.8.0 where imported; ByteMind package execution is unverified.
Standardize a constant column
The second training column is constant; transform a new value that differs from that constant.
from sklearn.preprocessing import StandardScalers = StandardScaler().fit([[2., 5.], [6., 5.]])print(s.mean_.tolist(), s.scale_.tolist())print(s.transform([[10., 7.]]).tolist())Expected output:
[4.0, 5.0] [2.0, 1.0][[3.0, 2.0]]The second scale is one, not zero; the new deviation is 2.
How it works
For training values 2 and 6, the mean is 4 and the population standard deviation is 2. The standardized values are -1 and 1. A new value 10 becomes 3; standardization does not constrain values to a fixed interval or make a distribution normal. StandardScaler uses population variance (ddof=0). With default centering, a training constant becomes zero; a different future value remains a deviation from that training constant. Such a change can signal drift. Min-max scaling instead uses the training minimum and range; with default range [0,1] values outside the training range can transform outside [0,1] unless clipping is chosen. Scaling often helps distance-based and regularized linear models; tree splits usually do not require scaling, but numerical effects and specific algorithms may differ. Fit each transformation within each training fold.
Inspect min-max extrapolation
Train on [2, 6] and transform 0 and 10 without clipping.
from sklearn.preprocessing import MinMaxScalers = MinMaxScaler().fit([[2.], [6.]])print(s.transform([[0.], [10.]]).ravel().tolist())Expected output:
[-0.5, 2.0]Values outside the training range may transform outside the configured interval.
Common mistakes
Never compute scale separately on the evaluation set. Do not divide by a zero standard deviation; specify a policy for constant columns and track schema changes. Avoid treating standardized features as bounded probabilities. Scaling does not correct data leakage, errors in units or missingness. Sparse matrices must not be centered if their implicit zeros are to remain sparse.
Practice and recap
Try apply fitted standardization. Input [means, scales, rows]. Means and scales are equally sized lists of finite numbers; scales are nonnegative fitted population standard deviations. Rows are finite numeric lists of matching width. Return scaled rows using (x-mean)/scale, substituting 1 for a zero scale. All fixture results are exact integers or binary fractions. Empty rows list returns []. Then explain the preprocessing assumptions before choosing a transformation. Next: Robust transformations.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Scaling and constant columns — knowledge check
Apply the preprocessing concept to small synthetic data and diagnose mistakes.
Training mean is 4 and standard deviation 2. What is standardized 10?
What scale does StandardScaler use for a zero-variance feature?
What does standardization guarantee?
What can min-max scaling do to a value above the training maximum when clip=False?
Where should scaling statistics be fitted in cross-validation?