Creates lagged versions of the target variable as new feature columns.
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: 112 NA NA NA
#> 2: 118 112 NA NA
#> 3: 132 118 112 NA
#> 4: 129 132 118 112
#> 5: 121 129 132 118
#> 6: 135 121 129 132