Normalize feature marginals
Features have strongly different, skewed marginal distributions.
Scikit-Learn · Class
QuantileTransformer maps each feature independently through an estimated quantile function to produce uniform or normal marginal distributions. It is a robust nonlinear preprocessing method that reduces the influence of marginal outliers.
For each feature independently, the transformer estimates its cumulative distribution from quantiles, maps values to the uniform scale, and then applies the quantile function of either a uniform or normal target distribution. This rank-based process reduces the influence of marginal outliers while changing the original feature geometry.
class sklearn.preprocessing.QuantileTransformer(*, n_quantiles=1000, output_distribution='uniform', ignore_implicit_zeros=False, subsample=10000, random_state=None, copy=True)| Name | Type | Description |
|---|---|---|
n_quantiles | int, default=1000 or n_samples | Number of quantile landmarks used to discretize the cumulative distribution; the default is 1000 or the number of samples. |
output_distribution | {'uniform', 'normal'}, default='uniform' | Target marginal distribution for transformed data: uniform or normal. |
ignore_implicit_zeros | bool, default=False | For sparse input, whether implicit zeros should be treated as stored zeros. |
subsample | int or None, default=10000 | Maximum number of samples used to estimate quantiles; subsampling can be controlled with this parameter. |
random_state | int, RandomState instance or None, default=None | Controls randomness used when subsampling data. |
copy | bool, default=True | Whether to copy the input instead of modifying it in place when possible. |
The class provides fitted transformation methods; fit_transform returns the transformed array, and transform returns data transformed using the fitted quantile mapping.
output_distribution, whose documented choices are uniform and normal.import numpy as np
from sklearn.preprocessing import QuantileTransformer
X = np.array([[1.0], [2.0], [3.0], [4.0], [5.0]])
transformer = QuantileTransformer(
n_quantiles=5, output_distribution="normal", random_state=0
)
X_transformed = transformer.fit_transform(X)
print(X_transformed.round(3))Fits the transformer on one feature and maps its values to an approximately normal marginal distribution.
Features have strongly different, skewed marginal distributions.
Marginal outliers should have less influence on preprocessing.
A model benefits from approximately Gaussian feature marginals.
It estimates each feature's cumulative distribution, maps the feature to uniform values, and then maps those values through the quantile function of the requested output distribution. The target can be uniform or normal.
Follow-up: What is the main robustness trade-off? The rank mapping reduces marginal-outlier influence, but it is nonlinear and can alter distances and relationships between features.
The n_quantiles setting controls how many quantile landmarks discretize the estimated cumulative distribution. Its effective default is 1000 or the number of samples, as documented.
Follow-up: Why might you reduce it? Fewer landmarks can make the mapping less finely fitted, which may help when data are limited or noisy.
output_distribution='uniform' maps features to a uniform marginal distribution, while 'normal' maps them to a normal marginal distribution. The default is uniform.
Follow-up: When is the normal option useful? It is useful when a downstream method benefits from approximately Gaussian marginal features, but it does not make the joint data distribution Gaussian.
quantile_transformPowerTransformerRobustScalerStandardScalerMinMaxScaler