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

Scikit-Learn · Class

QuantileTransformer

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.

How it works

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.

Syntax

class sklearn.preprocessing.QuantileTransformer(*, n_quantiles=1000, output_distribution='uniform', ignore_implicit_zeros=False, subsample=10000, random_state=None, copy=True)

Parameters

NameTypeDescription
n_quantilesint, default=1000 or n_samplesNumber 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_zerosbool, default=FalseFor sparse input, whether implicit zeros should be treated as stored zeros.
subsampleint or None, default=10000Maximum number of samples used to estimate quantiles; subsampling can be controlled with this parameter.
random_stateint, RandomState instance or None, default=NoneControls randomness used when subsampling data.
copybool, default=TrueWhether to copy the input instead of modifying it in place when possible.

Returns

The class provides fitted transformation methods; fit_transform returns the transformed array, and transform returns data transformed using the fitted quantile mapping.

Key points

  • QuantileTransformer is a preprocessing class that transforms feature values using estimated quantile information.
  • Each feature receives its own marginal quantile mapping rather than sharing one transformation across columns.
  • The first stage estimates a feature's cumulative distribution and converts its values to the uniform scale.
  • A second stage applies the inverse quantile function for the selected uniform or normal target distribution.
  • The rank-based preprocessing reduces the influence of marginal outliers, making it a robust scaling approach.
  • The target marginal distribution is selected with output_distribution, whose documented choices are uniform and normal.

Example: Map a feature to a normal distribution

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.

When to use it

Normalize feature marginals

Features have strongly different, skewed marginal distributions.

Reduce outlier influence

Marginal outliers should have less influence on preprocessing.

Map features to a normal distribution

A model benefits from approximately Gaussian feature marginals.

Interview questions

QHow does QuantileTransformer perform its transformation?

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.

QWhat does n_quantiles control?

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.

QWhat choices does output_distribution provide?

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_transform
  • PowerTransformer
  • RobustScaler
  • StandardScaler
  • MinMaxScaler

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