Besides Min-Max and Standardization, scikit-learn provides scalers for special situations.
1. Robust scaling
Uses the median and the interquartile range (IQR), so outliers barely influence it.
X_scaled = (X - median) / IQR
from sklearn.preprocessing import RobustScaler
rb = RobustScaler()
X_train_rb = rb.fit_transform(X_train[num_cols])
X_test_rb = rb.transform(X_test[num_cols])
Use it when the data contains outliers that you decided to keep.
2. Max-Abs scaling
Divides each feature by its maximum absolute value, mapping data to [-1, 1] without shifting or centering it. Zeros stay zeros, so it is ideal for sparse data.
from sklearn.preprocessing import MaxAbsScaler
ma = MaxAbsScaler()
X_train_ma = ma.fit_transform(X_train[num_cols])
X_test_ma = ma.transform(X_test[num_cols])
3. Unit-vector normalization (Normalizer)
Scales each row (sample) to have unit norm (length 1). It changes the sample, not the feature. Common for text vectors and cosine similarity.
from sklearn.preprocessing import Normalizer
norm = Normalizer(norm="l2") # each row gets length 1
X_norm = norm.fit_transform(X_train[num_cols].fillna(0))
4. Power transforms
Make skewed features more Gaussian, stabilizing variance.
- Box-Cox: positive values only.
- Yeo-Johnson: works for positive, zero and negative values.
from sklearn.preprocessing import PowerTransformer
pt = PowerTransformer(method="yeo-johnson")
X_train_pt = pt.fit_transform(X_train[["Fare"]])
X_test_pt = pt.transform(X_test[["Fare"]])
5. Quantile transform
Maps values to a uniform or normal distribution based on their rank. It is very robust against outliers but distorts distances between values.
from sklearn.preprocessing import QuantileTransformer
qt = QuantileTransformer(n_quantiles=100, output_distribution="normal", random_state=42)
X_train_qt = qt.fit_transform(X_train[["Fare"]])
X_test_qt = qt.transform(X_test[["Fare"]])
Comparison
| Scaler | Formula idea | Output | Outlier sensitivity | Typical use |
|---|---|---|---|---|
MinMaxScaler | (x - min)/(max - min) | [0, 1] | High | Neural nets, images |
StandardScaler | (x - mean)/std | Mean 0, std 1 | Medium | SVM, logistic regression, PCA |
RobustScaler | (x - median)/IQR | Unbounded | Low | Data with outliers |
MaxAbsScaler | x / max(abs(x)) | [-1, 1] | High | Sparse data |
Normalizer | row / row-norm | Unit length per row | Not applicable | Text, cosine similarity |
PowerTransformer | Box-Cox / Yeo-Johnson | Approximately Gaussian | Medium | Skewed features |
QuantileTransformer | Rank-based mapping | Uniform or normal | Very low | Heavy outliers, non-linear data |