AddMissingIndicator#

class feature_engine.imputation.AddMissingIndicator(missing_only=True, variables=None)[source]#

The AddMissingIndicator() adds binary variables that indicate if data is missing (one indicator per variable). The added variables (missing indicators) are named with the original variable name plus ‘_na’.

The AddMissingIndicator() works for both numerical and categorical variables. You can pass a list with the variables for which the missing indicators should be added. Alternatively, the imputer will select and add missing indicators to all variables in the training set.

Note If missing_only=True, the imputer will add missing indicators only to those variables that show missing data during fit(). These may be a subset of the variables you indicated in variables.

More details in the User Guide.

Parameters
missing_only: bool, default=True

If missing indicators should be added to variables with missing data or to all variables.

True: indicators will be created only for those variables that showed missing data during fit().

False: indicators will be created for all variables

variables: list, default=None

The list of variables to impute. If None, the imputer will find and select all variables.

Attributes
variables_:

List of variables for which the missing indicators will be created.

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.

Methods

fit:

Find the variables for which the missing indicators will be created

fit_transform:

Fit to data, then transform it.

get_feature_names_out:

Get output feature names for transformation.

get_params:

Get parameters for this estimator.

set_params:

Set the parameters of this estimator.

transform:

Add the missing indicators.

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

Learn the variables for which the missing indicators will be created.

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

The training dataset.

y: pandas Series, default=None

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

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.

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.

Parameters
input_features: list, default=None

Input features. If input_features is None, then the names of all the variables in the transformed dataset (original + new variables) is returned. Alternatively, only the names for the binary variables derived from input_features will be returned.

Returns
feature_names_out: list

The feature names.

:rtype:py:class:~typing.List
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.

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.

transform(X)[source]#

Add the binary missing indicators.

Parameters
Xpandas dataframe of shape = [n_samples, n_features]

The dataframe to be transformed.

Returns
X_newpandas dataframe of shape = [n_samples, n_features]

The dataframe containing the additional binary variables..

:rtype:py:class:~pandas.core.frame.DataFrame