Function to create a DirectForecaster object. This is the recommended way to construct a direct forecaster. It is a
thin wrapper around DirectForecaster$new().
A direct forecaster trains a separate regression model per forecast horizon, so predictions never feed back into one
another (no error accumulation). For the recursive strategy (a single iterated model) see recursive_forecaster().
Usage
direct_forecaster(
learner,
lags,
horizons,
id = NULL,
param_vals = list(),
predict_type = NULL
)Arguments
- learner
(mlr3::Learner | mlr3pipelines::Graph | mlr3pipelines::PipeOp)
A regression learner or a graph/PipeOp (without PipeOpFcstLags).- lags
(
integer())
The base lag values. Exposed in$param_setaslags, so it can be tuned via mlr3tuning::AutoTuner.- horizons
(
integer())
Either a single integerH(expanded to1:H) or an integer vector of specific horizons. One model is trained per horizon.- id
(
character(1)|NULL)
Identifier, defaultNULL(auto-generated from the learner id).- param_vals
(named
list())
Hyperparameter values applied to every horizon model. Per-horizon hyperparameters are not currently supported.- predict_type
(
character(1)|NULL)
The predict type, defaultNULL.
Examples
library(mlr3pipelines)
task = tsk("airpassengers")
split = partition(task, ratio = 0.8)
# one model per horizon
flrn = direct_forecaster(lrn("regr.rpart"), lags = 1:3, horizons = length(split$test))
flrn$train(task, split$train)
flrn$predict(task, split$test)
#>
#> ── <PredictionFcst> for 29 observations: ───────────────────────────────────────
#> month row_ids truth response
#> 1958-08-01 116 505 391.9375
#> 1958-09-01 117 404 324.7500
#> 1958-10-01 118 359 306.0000
#> --- --- --- ---
#> 1960-10-01 142 461 368.6875
#> 1960-11-01 143 390 364.9333
#> 1960-12-01 144 432 362.3571