Bound feature magnitudes
A model performs better or trains more consistently when numeric inputs occupy a bounded interval.
Scikit-Learn · Class
MinMaxScaler linearly maps each feature independently into a chosen interval, defaulting to [0, 1]. It learns feature extrema during fitting and reuses them for later transformations.
MinMaxScaler learns each feature's training-set minimum and maximum, maps those values into feature_range, and applies the same linear mapping to later data. It preserves feature ordering and relative linear spacing, but does not make distributions less sensitive to outliers.
class sklearn.preprocessing.MinMaxScaler(feature_range=(0, 1), *, copy=True, clip=False)| Name | Type | Description |
|---|---|---|
feature_range | tuple (min, max), default=(0, 1) | Desired range of transformed data. |
clip | bool, default=False | Set to True to clip transformed values of held-out data to the provided feature range. |
The class provides transformed arrays through its transform and fit_transform methods; the page documents learned attributes including data_min_, data_max_, data_range_, scale_, min_, n_features_in_, and n_samples_seen_.
from sklearn.preprocessing import MinMaxScaler
X_train = [[1., 10.], [2., 20.], [3., 30.]]
X_test = [[4., 25.]]
scaler = MinMaxScaler(feature_range=(-1, 1))
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
print(X_train_scaled)
print(X_test_scaled)Fit the scaler on training data, then reuse it to transform both training and held-out data.
A model performs better or trains more consistently when numeric inputs occupy a bounded interval.
Different columns use incompatible units or numeric scales.
A pipeline must apply identical preprocessing to training, validation, and production data.
An application requires transformed held-out values to stay within a prescribed interval.
It learns a separate minimum and maximum for every feature during fit, then linearly maps each feature into feature_range. The default target interval is [0, 1].
Follow-up: What happens to a value outside the training range? Unless clipping is enabled, the same linear mapping can produce a value outside feature_range.
The default feature_range is (0, 1), but a different two-element range can be supplied. The lower and upper values define the destination interval for each feature's fitted minimum and maximum.
Follow-up: Can the range be reversed? The documented parameter is a tuple (min, max), so callers should provide a valid intended lower-to-upper range.
It is sensitive to outliers because each feature's extrema determine the scale. It rescales outliers into the requested interval rather than reducing their influence.
Follow-up: When might another scaler be preferable? Choose a method whose documented behavior is more appropriate when extreme observations should not dominate the scaling.
StandardScalerRobustScalerMaxAbsScalerminmax_scale