DropFeatures#
- class feature_engine.selection.DropFeatures(features_to_drop)[source]#
DropFeatures() drops a list of variables indicated by the user from the dataframe.
More details in the User Guide.
- Parameters
- features_to_drop: str or list
Variable(s) to be dropped from the dataframe
- Attributes
- features_to_drop_:
The features that will be dropped.
- feature_names_in_:
List with the names of features seen during
fit
.- n_features_in_:
The number of features in the train set used in fit.
Examples
>>> import pandas as pd >>> from feature_engine.selection import DropFeatures >>> X = pd.DataFrame(dict(x1 = [1,2,3,4], >>> x2 = ["a", "a", "b", "c"], >>> x3 = [True, False, False, True])) >>> df = DropFeatures(features_to_drop=["x2"]) >>> df.fit_transform(X) x1 x3 0 1 True 1 2 False 2 3 False 3 4 True
Methods
fit:
This transformer does not learn any parameter.
fit_transform:
Fit to data, then transform it.
get_feature_names_out:
Get output feature names for transformation.
get_support:
Get a mask, or integer index, of the features selected.
get_params:
Get parameters for this estimator.
set_params:
Set the parameters of this estimator.
transform:
Drops indicated features.
- fit(X, y=None)[source]#
This transformer does not learn any parameter.
- Parameters
- Xpandas dataframe of shape = [n_samples, n_features]
The input dataframe
- ypandas Series, default = None
y is not needed for 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
andy
with optional parametersfit_params
and returns a transformed version ofX
.- Parameters
- 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).
- **fit_paramsdict
Additional fit parameters.
- Returns
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- get_feature_names_out(input_features=None)[source]#
Get output feature names for transformation. In other words, returns the variable names of transformed dataframe.
- Parameters
- input_featuresarray or list, default=None
This parameter exits only for compatibility with the Scikit-learn pipeline.
If
None
, thenfeature_names_in_
is used as feature names in.If an array or list, then
input_features
must matchfeature_names_in_
.
- Returns
- feature_names_out: list
Transformed feature names.
- get_params(deep=True)[source]#
Get parameters for this estimator.
- Parameters
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsdict
Parameter names mapped to their values.
- get_support(indices=False)[source]#
Get a mask, or integer index, of the features selected.
- Parameters
- indicesbool, default=False
If True, the return value will be an array of integers, rather than a boolean mask.
- Returns
- supportarray
An index that selects the retained features from a feature vector. If
indices
is False, this is a boolean array of shape [# input features], in which an element is True if its corresponding feature is selected for retention. Ifindices
is True, this is an integer array of shape [# output features] whose values are indices into the input feature vector.
- set_params(**params)[source]#
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.- Parameters
- **paramsdict
Estimator parameters.
- Returns
- selfestimator instance
Estimator instance.