Skip to contents

Creates a RecursiveForecaster (recursive strategy) or DirectForecaster (direct strategy), selected via strategy.

Usage

as_learner_fcst(
  learner,
  lags = NULL,
  strategy = "recursive",
  horizons = NULL,
  ...
)

Arguments

learner

(mlr3::Learner | mlr3pipelines::Graph | mlr3pipelines::PipeOp)
A regression learner (when lags is provided) or a graph/PipeOp.

lags

(integer() | NULL)
The lag values to use for creating lag features.

strategy

(character(1))
Forecasting strategy. One of "recursive" (default) or "direct".

horizons

(integer() | NULL)
Required when strategy = "direct"; must be NULL when strategy = "recursive". A single integer H is expanded to 1:H.

...

(any)
Additional arguments passed to RecursiveForecaster or DirectForecaster.

Examples

library(mlr3pipelines)

# recursive forecasting (default)
flrn = as_learner_fcst(lrn("regr.rpart"), lags = 1:3)

# recursive with a custom graph
graph = po("fcst.lags", lags = 1:3) %>>% lrn("regr.rpart")
flrn = as_learner_fcst(graph)

# direct forecasting (one model per horizon)
flrn = as_learner_fcst(lrn("regr.rpart"), lags = 1:3, strategy = "direct", horizons = 12)