Create Rolling Window Features of Target Variable
Source:R/PipeOpFcstRolling.R
mlr_pipeops_fcst.rolling.RdCreates rolling-window summary statistics of the target variable as new feature columns.
The window ends at position t - lag (exclusive of the current and lag - 1 most recent
values) and has size window_size.
Parameters
The parameters are the parameters inherited from mlr3pipelines::PipeOpTaskPreproc, as well as the following parameters:
funs::character()
Aggregation functions. Subset ofc("mean", "median", "sd", "min", "max", "sum"). Default"mean".window_sizes::integer()
Window sizes. Every combination offunsandwindow_sizesproduces one output column. Default3L.lag::integer(1)
Minimum lag before the window starts. Must be>= 1to avoid leakage. Default1L.
Super classes
mlr3pipelines::PipeOp -> mlr3pipelines::PipeOpTaskPreproc -> PipeOpFcstRolling
Methods
Method new()
Initializes a new instance of this Class.
Usage
PipeOpFcstRolling$new(id = "fcst.rolling", param_vals = list())Examples
library(mlr3pipelines)
task = tsk("airpassengers")
po = po("fcst.rolling", funs = c("mean", "sd"), window_sizes = c(3L, 12L))
new_task = po$train(list(task))[[1L]]
new_task$head()
#> passengers passengers_roll_mean_3 passengers_roll_mean_12
#> <num> <num> <num>
#> 1: 112 NA NA
#> 2: 118 NA NA
#> 3: 132 NA NA
#> 4: 129 120.6667 NA
#> 5: 121 126.3333 NA
#> 6: 135 127.3333 NA
#> passengers_roll_sd_3 passengers_roll_sd_12
#> <num> <num>
#> 1: NA NA
#> 2: NA NA
#> 3: NA NA
#> 4: 10.263203 NA
#> 5: 7.371115 NA
#> 6: 5.686241 NA