liveBook · Manning

RobustScaler

As explained in Outlier Detection in Python

Robust scaling transforms feature values using robust location and spread statistics, typically the median and interquartile range, to reduce sensitivity to extreme values.

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

How Outlier Detection in Python covers it

How deep it goes
Defines median-and-IQR scaling, demonstrates implementation, and compares detector effects, but defers detailed scaling theory.
Examples
Demonstrates baseball feature scaling, nearest-neighbor comparisons, injected outliers, and PyOD score combination.
What it assumes
Assumes numeric inputs and prior categorical encoding; requires choosing one consistent scaling method across features.
What you can do after
Apply it via scikit-learn to create comparable numeric features or scaled detector scores while retaining relative distributions.
How it connects
Connects feature scaling with standard scaling, min-max scaling, nearest neighbors, radius-based detection, and ensemble methods.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.