Outlier-resistant scaling
Feature preprocessing for datasets containing a small number of extreme values.
Scikit-Learn · Class
RobustScaler centers features by their median and scales them using a configurable quantile range. Its default interquartile-range statistics are less affected by outliers than mean-and-variance scaling.
RobustScaler centers each feature with its training median and scales it using a selected percentile interval. By default, that interval is the interquartile range between the 25th and 75th percentiles, making the fitted statistics less sensitive to extreme values.
class sklearn.preprocessing.RobustScaler(*, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False)| Name | Type | Description |
|---|---|---|
with_centering | bool | Whether to subtract each feature’s median before scaling; default is True. |
with_scaling | bool | Whether to scale each feature to the selected quantile interval; default is True. |
quantile_range | tuple (q_min, q_max) | Lower and upper percentile bounds used to compute the scale; default is (25.0, 75.0). |
copy | bool | Whether to modify a copy of the input when possible; default is True. |
unit_variance | bool | Whether to normalize the scale so normally distributed features have variance one; default is False. |
A fitted RobustScaler instance from fit; transformed array-like data from transform and fit_transform.
unit_variance=True adjusts the scaling target for features assumed to be normally distributed.from sklearn.preprocessing import RobustScaler
X = [[1.0, 10.0], [2.0, 12.0], [3.0, 11.0], [100.0, 13.0]]
scaler = RobustScaler()
X_scaled = scaler.fit_transform(X)
print(X_scaled)Fits robust per-feature statistics on the training rows, then transforms the same data using those statistics.
Feature preprocessing for datasets containing a small number of extreme values.
Preparing independently measured numeric columns for models sensitive to feature scale.
Replacing ordinary mean-and-variance scaling when outliers make those estimates unreliable.
RobustScaler subtracts each feature’s median and divides by a scale derived from a configurable quantile interval. Its default interval is the interquartile range, from the 25th to the 75th percentile, so extreme observations have less effect on the fitted center and scale.
Follow-up: How would you handle sparse input? Fit RobustScaler on dense data, because the class cannot fit sparse input; after fitting, its transform operation can accept sparse input.
quantile_range control?The default quantile interval is (25.0, 75.0), which is the interquartile range. The tuple must satisfy 0.0 < q_min < q_max < 100.0, and changing it changes the interval used to calculate scale_.
Follow-up: What does unit_variance=True change? It rescales the result so normally distributed features would have variance one, based on the selected quantile range.
with_centering and with_scaling do?with_centering controls median subtraction, while with_scaling controls scaling to the selected quantile interval. Both default to True, so the default operation performs both steps independently for every feature.
Follow-up: Can centering and scaling be disabled independently? Yes: set either option to False to omit that respective operation.
StandardScalerMinMaxScalerPowerTransformerQuantileTransformer