ArbitraryNumberImputer#
- class feature_engine.imputation.ArbitraryNumberImputer(arbitrary_number=999, variables=None, imputer_dict=None)[source]#
The ArbitraryNumberImputer() replaces missing data by an arbitrary value determined by the user. It works only with numerical variables.
You can impute all variables with the same number by defining the variables to impute in
variables
and the imputation number inarbitrary_number
. Alternatively, you can pass a dictionary with the variable names and the numbers to use for their imputation in theimputer_dict
parameter.More details in the User Guide.
- Parameters
- arbitrary_number: int or float, default=999
The number to replace the missing data. This parameter is used only if
imputer_dict
is None.- variables: list, default=None
The list of variables to impute. If None, the imputer will select all numerical variables. This parameter is used only if
imputer_dict
is None.- imputer_dict: dict, default=None
The dictionary of variables and the arbitrary numbers for their imputation. If specified, it overrides the above parameters.
- Attributes
- imputer_dict_:
Dictionary with the values to replace NAs in each variable.
- variables_:
The group of variables that will be transformed.
- n_features_in_:
The number of features in the train set used in fit.
Methods
fit:
This transformer does not learn parameters.
transform:
Impute missing data.
fit_transform:
Fit to the data, then transform it.
- fit(X, y=None)[source]#
This method does not learn any parameter.
- Parameters
- X: pandas dataframe of shape = [n_samples, n_features]
The training dataset.
- y: 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
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_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]#
Replace missing data with the learned parameters.
- Parameters
- X: pandas dataframe of shape = [n_samples, n_features]
The data to be transformed.
- Returns
- X_new: pandas dataframe of shape = [n_samples, n_features]
The dataframe without missing values in the selected variables.
- :rtype:py:class:
~pandas.core.frame.DataFrame