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.
Install the development version from GitHub:
remotes::install_github("mlr-org/mlr3temporal")
Currently the following methods are implemented:
Id | Code | Type |
---|---|---|
airpassengers | tsk("airpassengers") |
Univariate Timeseries |
petrol | tsk("petrol") |
Multivariate Timeseries |
Id | Learner | Package |
---|---|---|
forecast.auto_arima | Auto Arima | forecast |
forecast.arima | Arima | forecast |
forecast.average | Average | base |
forecast.VAR | Vector Autoregression | vars |
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 |
Id | Resampling | Package |
---|---|---|
forecast_holdout | Holdout | base |
forecast_cv | Rolling Window CrossValidation | base |
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)
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"))
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"))
For detailed information on how to get started with mlr3
please read
the mlr3 book and consult the
Vignette for
more examples of mlr3temporal.
Please consult the wiki for a style guide, a roxygen guide and a pull request guide.