This R package provides tools for machine-learning based time-series prediction. This includes preprocessing, creating matrices of lags, building a pipeline, and specialized cross-validation.
You can install the latest version from Github:
if (!require("devtools")) install.packages("devtools")
devtools::install_github("fnoorian/mltsp")
This package includes two vignettes:
- NARX model guide: Simple solution for non-linear auto-regressive forecasting.
- Pipeline model guide: Introduces pipeline model and cross-validation tools.
To build a non-linear auto-regressive model for
lh
(Luteinizing Hormone in Blood Samples, datasets
package) with
- differencing order
d = 0
, - auto-regressive order
p = 3
, - seasonal frequency
freq = 1
, - seasonal differencing order
D =0
, - seasonal order
P = 0
, svm
learner from package e1071,- No external regressor
use:
library("mltsp")
library("e1071")
spec = build_narx(svm, p = 3, d = 0, P = 0, D = 0, freq = 1)
model = narx(spec, lh, xreg = NULL)
These steps can be combined into one (and default values can used):
model = narx(lh, svm, p = 3)
To predict 5 steps ahead, simply use:
forecast(model, h = 5)
Output is compatible with package forecast.
To build a pipeline for predicting
lh
(Luteinizing Hormone in Blood Samples from datasets
package) with
- Preprocessing: differencing with order automatically determined
- Features: three lags of input data
- Learner: a linear model
use:
library("mltsp")
pp <- list(list("diff", "auto"))
fx <- function(x) cbind(x, lag_windows(x, p = 3))
ln <- SimpleLM
fcster <- mltsp_forecaster(pp, fx, ln)
and then apply function fcster
to data:
fcster(lh, h = 5)
To get cross-validation score for fcster
function for a horizon of 5 steps,
with training on at least 10 data points, use:
ts_crossval(lh, fcster, horizon = 5, initial_window = 10)
Copyright 2016 Farzad Noorian [email protected], Richard Davis [email protected], Anthony Mihirana de Silva [email protected], Lei Li [email protected].
Some functionality have been taken from GPL package caret.
For a list of other functions dynamically imported from other R packages, see NAMESPACE
file.
This package is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this package. If not, see http://www.gnu.org/licenses/.