Extending mlr3 to time series forecasting.
This package is in an early stage of development and should be considered experimental.
Install the development version from GitHub:
# install.packages("pak")
pak::pak("mlr-org/mlr3forecast")
library(mlr3forecast)
#> Loading required package: mlr3
library(mlr3learners)
dt = tsbox::ts_dt(AirPassengers)
dt[, time := NULL]
task = as_task_regr(dt, target = "value")
ff = Forecaster$new(
learner = lrn("regr.ranger"),
lag = 1:3
)
ff$train(task)
prediction = ff$predict(task)
prediction
#> <PredictionRegr> for 144 observations:
#> row_ids truth response
#> 1 432.0000 404.1487
#> 2 404.1487 450.5137
#> 3 450.5137 420.9816
#> ---
#> 142 452.6298 454.5250
#> 143 454.5250 454.5353
#> 144 454.5353 445.7902
prediction = ff$predict_newdata(task, 3L)
prediction
#> <PredictionRegr> for 3 observations:
#> row_ids truth response
#> 1 NA 404.1487
#> 2 NA 450.5137
#> 3 NA 420.9816
prediction = ff$predict(task, 142:144)
prediction
#> <PredictionRegr> for 3 observations:
#> row_ids truth response
#> 1 508.0000 498.0064
#> 2 498.0064 460.8071
#> 3 460.8071 445.5276
prediction$score(msr("regr.rmse"))
#> regr.rmse
#> 23.92435