RobustScaler transforms numeric features with the median and interquartile range (IQR), producing comparable scales while preserving the data’s relative distribution. section 4.10 section 9.5
Use robust scaling before distance-, density-, or clustering-based outlier detectors when features have different units or extreme values. Unlike mean and standard deviation, the median and IQR resist distortion from extremes. section 4.10 section 9.5
Practical trade-offs:
- Scale every feature with the same method; different scalers can change nearest neighbors, distances, and radius-based detector membership. section 9.5
- Encode categorical variables before scaling because RobustScaler operates on numeric data. section 4.10
- Expect extreme values to remain extreme; when scaling detector scores for ensembles, they can still dominate combined scores. section 14.5.3
Scale a numeric DataFrame
from sklearn.preprocessing import RobustScaler scaler = RobustScaler() df = pd.DataFrame(scaler.fit_transform(df), columns=df.columns) The baseball example changes features such as games played, at bats, runs, and hits to comparable scales without changing their distributions.
Scale scores before ensembling
Apply RobustScaler independently to detector-score columns before combining them with PyOD’s aom method. This standardizes score magnitudes, but does not remove extreme scores. section 14.6.2
