Temporal prediction / forecasting for mlr3

Time series analysis accounts for the fact that data points taken over time may have an internal structure (such as autocorrelation, trend or seasonal variation) that should be accounted for. This package extends the mlr3 package framework by time-series prediction and resampling methods.

Installation

Install the development version from GitHub:

remotes::install_github("mlr-org/mlr3temporal")

Forecasting

Currently the following methods are implemented:

Tasks

Id Code Type
airpassengers tsk("airpassengers") Univariate Timeseries
petrol tsk("petrol") Multivariate Timeseries

Learners

Id Learner Package
forecast.auto_arima Auto Arima forecast
forecast.arima Arima forecast
forecast.average Average base
forecast.VAR Vector Autoregression vars

Measures

Id Measure Package
forecast.mae Mean Absolute Error base
forecast.mape Mean Absolute Percentage Error base
forecast.mse Mean Squared Error base
forecast.rmse Root Mean Squared Error base

Resampling Methods

Id Resampling Package
forecast_holdout Holdout base
forecast_cv Rolling Window CrossValidation base

Code Example

library(mlr3temporal)

task = tsk("airpassengers")
learner = lrn("forecast.auto_arima")
learner$train(task, row_ids = 1:20)
predictions = learner$predict(task, row_ids = 21:55)
measure = msr("forecast.mae")
predictions$score(measure)
autoplot(task)

Resampling

Holdout

Split data into a training set and a test set. Parameter ratio determines the ratio of observation going into the training set (default: 2/3).

task = tsk("petrol")
learner = lrn("forecast.VAR")
resampling = rsmp("forecast_holdout", ratio = 0.8)
rr = resample(task, learner, resampling, store_models = TRUE)
rr$aggregate(msr("forecast.mae"))

Rolling Window CV

Splits data using a folds-folds (default: 10 folds) rolling window cross-validation.

task = tsk("petrol")
learner = lrn("forecast.VAR")
resampling = rsmp("forecast_cv", folds = 5, fixed_window = FALSE)
rr = resample(task, learner, resampling, store_models = TRUE)
rr$aggregate(msr("forecast.mae"))

More resources

For detailed information on how to get started with mlr3 please read the mlr3 book and consult the Vignette for more examples of mlr3temporal.

Contributing to mlr3temporal

Please consult the wiki for a style guide, a roxygen guide and a pull request guide.