Back to models
Transformer

Imputer

MultivariateInverse transformMissing valuesMissing values removesUnequal length

Missing value imputation.

Quickstart

python
from sktime.transformations.impute import Imputer

estimator = Imputer(method='drift', random_state=None, value=None, forecaster=None, missing_values=None)

Parameters(5)

methodstr, default=”drift”

Method to fill the missing values. Not all methods can extrapolate, so after method is applied the remaining missing values are filled with ffill then bfill.

  • “drift”: drift/trend values by sktime.PolynomialTrendForecaster(degree=1) first, X in transform() is filled with ffill then bfill then PolynomialTrendForecaster(degree=1) is fitted to filled X, and predict values are queried at indices which had missing values

  • “linear”linear interpolation, uses pd.Series.interpolate()

    WARNING: This method can not extrapolate, so it is fitted always on the data given to transform().

missing_valuesstr, int, float, regex, list, or None, default=None

Value to consider as np.nan` and impute, passed to DataFrame.replace If str, int, float, all entries equal to missing_values will be imputed, in addition to np.nan. If regex, all entries matching regex will be imputed, in addition to np.nan. If list, must be list of str, int, float, or regex. Values matching any list element by above rules will be imputed, in addition to np.nan. If None, then only np.nan values are imputed.

valueint/float, default=None

Value to use to fill missing values when method=”constant”. Only used if method="constant", otherwise ignored.

forecasterAny Forecaster based on sktime.BaseForecaster, default=None

Use a given Forecaster to impute by insample predictions when method="forecaster". Before fitting, missing data is imputed with method="ffill" or "bfill" as heuristic. In case of multivariate X, a clone of forecaster is applied per column. Only used if method="forecaster", otherwise ignored.

random_stateint/float/str, optional
Value to set random.seed() if method=”random”, default None

Examples

>>> from sktime.transformations.impute import Imputer
>>> from sktime.datasets import load_airline
>>> from sktime.split import temporal_train_test_split
>>> y = load_airline ()
>>> y_train, y_test = temporal_train_test_split (y)
>>> transformer = Imputer (method = "drift")
>>> transformer. fit (y_train) Imputer(
... )
>>> import numpy as np
>>> y_test. iloc [3 ] = np. nan
>>> y_hat = transformer. transform (y_test)