Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

RobustScaler

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.

How it works

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.

Syntax

class sklearn.preprocessing.RobustScaler(*, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True, unit_variance=False)

Parameters

NameTypeDescription
with_centeringboolWhether to subtract each feature’s median before scaling; default is True.
with_scalingboolWhether to scale each feature to the selected quantile interval; default is True.
quantile_rangetuple (q_min, q_max)Lower and upper percentile bounds used to compute the scale; default is (25.0, 75.0).
copyboolWhether to modify a copy of the input when possible; default is True.
unit_varianceboolWhether to normalize the scale so normally distributed features have variance one; default is False.

Returns

A fitted RobustScaler instance from fit; transformed array-like data from transform and fit_transform.

Key points

  • Use this transformer when extreme observations could distort ordinary center-and-spread estimates.
  • Its default scale interval is the interquartile range, bounded by the first and third quartiles.
  • Each column receives its own median and scale rather than sharing statistics across columns.
  • After fitting, the learned statistics are reused to transform later samples consistently.
  • unit_variance=True adjusts the scaling target for features assumed to be normally distributed.

Common mistakes

  • With unit_variance enabled, the chosen interval can cause values to be enlarged when its width is below the normal-distribution reference width.

Example: Scale features with outlier-resistant statistics

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.

When to use it

Outlier-resistant scaling

Feature preprocessing for datasets containing a small number of extreme values.

Per-feature normalization

Preparing independently measured numeric columns for models sensitive to feature scale.

Robust drop-in preprocessing

Replacing ordinary mean-and-variance scaling when outliers make those estimates unreliable.

Interview questions

QHow does RobustScaler differ from mean-and-variance scaling?

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.

QWhat does 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.

QWhat do 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.

  • StandardScaler
  • MinMaxScaler
  • PowerTransformer
  • QuantileTransformer

Source: RobustScaler — scikit-learn 1.9.1 documentation. Checked 2026-10-15.