Imputer
Missing value imputation.
Quickstart
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
methodis applied the remaining missing values are filled withffillthenbfill.“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.replaceIf str, int, float, all entries equal tomissing_valueswill be imputed, in addition tonp.nan.If regex, all entries matching regex will be imputed, in addition tonp.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 tonp.nan. If None, then onlynp.nanvalues 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 withmethod="ffill"or"bfill"as heuristic. In case of multivariate X, a clone offorecasteris applied per column. Only used ifmethod="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)