class feature_engine.selection.RecursiveFeatureElimination(estimator, scoring='roc_auc', cv=3, threshold=0.01, variables=None)[source]#

RecursiveFeatureElimination() selects features following a recursive elimination process.

The process is as follows:

  1. Train an estimator using all the features.

  2. Rank the features according to their importance derived from the estimator.

  3. Remove the least important feature and fit a new estimator.

  4. Calculate the performance of the new estimator.

  5. Calculate the performance difference between the new and original estimator.

  6. If the performance drop is below the threshold the feature is removed.

  7. Repeat steps 3-6 until all features have been evaluated.

Model training and performance evaluation are done with cross-validation.

More details in the User Guide.

estimator: object

A Scikit-learn estimator for regression or classification. The estimator must have either a feature_importances or coef_ attribute after fitting.

variables: str or list, default=None

The list of variable to be evaluated. If None, the transformer will evaluate all numerical features in the dataset.

scoring: str, default=’roc_auc’

Desired metric to optimise the performance of the estimator. Comes from sklearn.metrics. See the model evaluation documentation for more options:

threshold: float, int, default = 0.01

The value that defines if a feature will be kept or removed. Note that for metrics like roc-auc, r2_score and accuracy, the thresholds will be floats between 0 and 1. For metrics like the mean_square_error and the root_mean_square_error the threshold can be a big number. The threshold must be defined by the user. Bigger thresholds will select less features.

cv: int, cross-validation generator or an iterable, default=3

Determines the cross-validation splitting strategy. Possible inputs for cv are:

For int/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used. These splitters are instantiated with shuffle=False so the splits will be the same across calls. For more details check Scikit-learn’s cross_validate’s documentation.


Performance of the model trained using the original dataset.


Pandas Series with the feature importance (comes from step 2)


Dictionary with the performance drift per examined feature (comes from step 5).


List with the features to remove from the dataset.


The variables that will be considered for the feature selection.


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



Find the important features.


Reduce X to the selected features.


Fit to data, then transform it.

fit(X, y)[source]#

Find the important features. Note that the selector trains various models at each round of selection, so it might take a while.

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

The input dataframe

y: array-like of shape (n_samples)

Target variable. Required to train the estimator.

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


Return dataframe with selected features.

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

The input dataframe.

X_new: pandas dataframe of shape = [n_samples, n_selected_features]

Pandas dataframe with the selected features.