Creates lagged versions of the target variable as new feature columns.
At train time the first rows of each series have no history for the requested lags. These
incomplete rows are dropped (the autoregressive-fit convention), so the base learner never sees
NA lags. A keyed series shorter than the largest lag is dropped entirely, with a warning.
At predict time, lags are computed from the task's full backend (i.e. including rows outside
row_roles$use), then joined onto the active rows. Used inside RecursiveForecaster, where the
forecaster writes each step's prediction into the combined task's target column between steps so
lag features for the next step reflect the freshly predicted value.
Parameters
The parameters are the parameters inherited from mlr3pipelines::PipeOpTaskPreproc, as well as the following parameters:
lags::integer()
The lags to create.
Super classes
mlr3pipelines::PipeOp -> mlr3pipelines::PipeOpTaskPreproc -> PipeOpFcstLags
Methods
PipeOpFcstLags$new()
Initializes a new instance of this Class.
Usage
PipeOpFcstLags$new(id = "fcst.lags", param_vals = list())Examples
library(mlr3pipelines)
task = tsk("airpassengers")
po = po("fcst.lags", lags = 1:3)
new_task = po$train(list(task))[[1L]]
new_task$head()
#> passengers passengers_lag_1 passengers_lag_2 passengers_lag_3
#> <num> <num> <num> <num>
#> 1: 129 132 118 112
#> 2: 121 129 132 118
#> 3: 135 121 129 132
#> 4: 148 135 121 129
#> 5: 148 148 135 121
#> 6: 136 148 148 135