RobustScaler
Centers and scales features using statistics that are robust to outliers: the median for centering and the interquartile range (IQR) for scaling.
Formula
where:
- is the median of feature
- is the interquartile range
Unlike StandardScaler, the median and IQR are not influenced by extreme values, so the scaling remains stable even with outliers in the data.
When to Use
- Data with outliers: When the data contains extreme values that would distort mean/variance-based scaling.
- Robust pipelines: As a preprocessing step before models sensitive to feature scales.
- The
quantile_rangeparameter allows customizing the centering quantiles (e.g., using the 5th and 95th percentiles).
Mirrors sklearn.preprocessing.RobustScaler.
Constructor
Skigen::RobustScaler<Scalar> scaler(bool with_centering = true,
bool with_scaling = true,
{q_min, q_max} = {25, 75});
| Parameter | Default | Description |
|---|---|---|
with_centering | true | Center by median |
with_scaling | true | Scale by IQR |
quantile_range | {25, 75} | Quantile range for scaling |
Methods
| Method | Description |
|---|---|
fit(X) | Compute median and IQR |
transform(X) | Scale using median and IQR |
inverse_transform(Z) | Recover original scale |
transform_inplace(X) | Scale in-place |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
center() | RowVectorType | Per-feature median |
scale() | RowVectorType | Per-feature IQR |
Example
#include <Skigen/Preprocessing>
Skigen::RobustScaler scaler;
scaler.fit(X);
auto X_scaled = scaler.transform(X);