class feature_engine.outliers.Winsorizer(capping_method='gaussian', tail='right', fold=3, add_indicators=False, variables=None, missing_values='raise')[source]#

The Winsorizer() caps maximum and/or minimum values of a variable at automatically determined values, and optionally adds indicators.

The extreme values beyond which an observation is considered an outlier are determined using:

  • a Gaussian approximation

  • the inter-quantile range proximity rule (IQR)

  • percentiles

Gaussian limits:

  • right tail: mean + 3* std

  • left tail: mean - 3* std

IQR limits:

  • right tail: 75th quantile + 3* IQR

  • left tail: 25th quantile - 3* IQR

where IQR is the inter-quartile range: 75th quantile - 25th quantile.


  • right tail: 95th percentile

  • left tail: 5th percentile

You can select how far out to cap the maximum or minimum values with the parameter 'fold'.

If capping_method='gaussian' fold gives the value to multiply the std.

If capping_method='iqr' fold is the value to multiply the IQR.

If capping_method='quantiles', fold is the percentile on each tail that should be censored. For example, if fold=0.05, the limits will be the 5th and 95th percentiles. If fold=0.1, the limits will be the 10th and 90th percentiles.

The Winsorizer() works only with numerical variables. A list of variables can be indicated. Alternatively, the Winsorizer() will select and cap all numerical variables in the train set.

The transformer first finds the values at one or both tails of the distributions (fit). The transformer then caps the variables (transform).

More details in the User Guide.

capping_method: str, default=’gaussian’

Desired outlier detection method. Can take ‘gaussian’, ‘iqr’ or ‘quantiles’.

The transformer will find the maximum and / or minimum values beyond which a data point will be considered an outlier using: ‘gaussian’: the Gaussian approximation. ‘iqr’: the IQR proximity rule. ‘quantiles’: the percentiles.

tail: str, default=’right’

Whether to look for outliers on the right, left or both tails of the distribution. Can take ‘left’, ‘right’ or ‘both’.

fold: int or float, default=3

The factor used to multiply the std or IQR to calculate the maximum or minimum allowed values. Recommended values are 2 or 3 for the gaussian approximation, and 1.5 or 3 for the IQR proximity rule.

If capping_method='quantile', then 'fold' indicates the percentile. So if fold=0.05, the limits will be the 95th and 5th percentiles.

Note: Outliers will be removed up to a maximum of the 20th percentiles on both sides. Thus, when capping_method='quantile', then 'fold' takes values between 0 and 0.20.

add_indicators: bool, default=False

Whether to add indicator variables to flag the capped outliers. If ‘True’, binary variables will be added to flag outliers on the left and right tails of the distribution. One binary variable per tail, per variable.

variables: list, default=None

The list of numerical variables to transform. If None, the transformer will automatically find and select all numerical variables.

missing_values: string, default=’raise’

Indicates if missing values should be ignored or raised. If ‘raise’ the transformer will return an error if the the datasets to fit or transform contain missing values. If ‘ignore’, missing data will be ignored when learning parameters or performing the transformation.


Dictionary with the maximum values beyond which a value will be considered an outlier.


Dictionary with the minimum values beyond which a value will be considered an outlier.


The group of variables that will be transformed.


List with the names of features seen during fit.


The number of features in the train set used in fit.



Learn the values that will replace the outliers.


Fit to data, then transform it.


Get output feature names for transformation.


Get parameters for this estimator.


Set the parameters of this estimator.


Cap the variables.

fit(X, y=None)[source]#

Learn the values that should be used to replace outliers.

Xpandas dataframe of shape = [n_samples, n_features]

The training input samples.

ypandas Series, default=None

y is not needed in this transformer. You can pass y or None.

fit_transform(X, y=None, **fit_params)[source]#

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).


Additional fit parameters.

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.


Get output feature names for transformation.

input_features: str, list, default=None

If None, then the names of all the variables in the transformed dataset is returned. If list with feature names, the features in the list, plus the outlier indicators (if added), will be returned.

feature_names_out: list

The feature names.

:rtype:py:class:~typing.List[Union[str, int]]

Get parameters for this estimator.

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.


Parameter names mapped to their values.


Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.


Estimator parameters.

selfestimator instance

Estimator instance.


Cap the variable values. Optionally, add outlier indicators.

X: pandas dataframe of shape = [n_samples, n_features]

The data to be transformed.

X_new: pandas dataframe of shape = [n_samples, n_features + n_ind]

The dataframe with the capped variables and indicators. The number of output variables depends on the values for ‘tail’ and ‘add_indicators’: if passing ‘add_indicators=False’, will be equal to ‘n_features’, otherwise, will have an additional indicator column per processed feature for each tail.