Autoregressive forecasting using various Machine Learning models.
ARml(
y,
max_lag = 5,
xreg = NULL,
caret_method = "cubist",
metric = "RMSE",
pre_process = NULL,
cv = TRUE,
cv_horizon = 4,
initial_window = NULL,
fixed_window = FALSE,
verbose = TRUE,
seasonal = TRUE,
K = frequency(y)/2,
tune_grid = NULL,
lambda = NULL,
BoxCox_method = c("guerrero", "loglik"),
BoxCox_lower = -1,
BoxCox_upper = 2,
BoxCox_biasadj = FALSE,
BoxCox_fvar = NULL,
allow_parallel = FALSE,
calibrate = TRUE,
calibration_horizon = NULL,
n_cal_windows = NULL,
...
)A list class of forecast containing the following elemets
x : The input time series
method : The name of the forecasting method as a character string
mean : Point forecasts as a time series
lower : Lower limits for prediction intervals
upper : Upper limits for prediction intervals
level : The confidence values associated with the prediction intervals
model : A list containing information about the fitted model
newx : A matrix containing regressors
calibration : Horizon-specific conformal calibration scores (if calibrate=TRUE)
A univariate time series object.
Maximum value of lag.
Optional. A numerical vector or matrix of external regressors, which must have the same number of rows as y. (It should not be a data frame.).
A string specifying which classification or regression model to use. Possible values are found using names(getModelInfo()). A list of functions can also be passed for a custom model function. See https://topepo.github.io/caret/ for details.
A string that specifies what summary metric will be used to
select the optimal model. See ?caret::train.
A string vector that defines a pre-processing of the predictor data. Current possibilities are "BoxCox", "YeoJohnson", "expoTrans", "center", "scale", "range", "knnImpute", "bagImpute", "medianImpute", "pca", "ica" and "spatialSign". The default is no pre-processing. See preProcess and trainControl on the procedures and how to adjust them. Pre-processing code is only designed to work when x is a simple matrix or data frame.
Logical, if cv = TRUE model selection will be done via
cross-validation. If cv = FALSE user need to provide a specific model
via tune_grid argument.
The number of consecutive values in test set sample.
The initial number of consecutive values in each training set sample.
Logical, if FALSE, all training samples start at 1.
A logical for printing a training log.
Boolean. If seasonal = TRUE the fourier terms will be
used for modeling seasonality.
Maximum order(s) of Fourier terms
A data frame with possible tuning values. The columns are named the same as the tuning parameters. Use getModelInfo to get a list of tuning parameters for each model or see https://topepo.github.io/caret/available-models.html. (NOTE: If given, this argument must be named.)
BoxCox transformation parameter. If lambda = NULL
If lambda = "auto", then the transformation parameter lambda is chosen
using BoxCox.lambda.
BoxCox.lambda argument.
Choose method to be used in calculating lambda.
BoxCox.lambda argument.
Lower limit for possible lambda values.
BoxCox.lambda argument.
Upper limit for possible lambda values.
InvBoxCox argument.
Use adjusted back-transformed mean for Box-Cox transformations.
If transformed data is used to produce forecasts and fitted values,
a regular back transformation will result in median forecasts.
If biasadj is TRUE, an adjustment will be made to produce mean
forecasts and fitted values.
InvBoxCox argument.
Optional parameter required if biasadj=TRUE.
Can either be the forecast variance, or a list containing the interval level,
and the corresponding upper and lower intervals.
If a parallel backend is loaded and available, should the function use it?
Logical. If TRUE, performs rolling-origin calibration to compute horizon-specific conformal prediction intervals. This produces properly calibrated intervals that widen with forecast horizon (trumpet shape). Default is TRUE.
Maximum forecast horizon for calibration.
If NULL (default), uses 2 * frequency(y) for seasonal data or 10
for non-seasonal data.
Number of rolling windows for calibration. If NULL (default), automatically determined based on data length (max 50).
Ignored.
Resul Akay
library(caretForecast)
train_data <- window(AirPassengers, end = c(1959, 12))
test <- window(AirPassengers, start = c(1960, 1))
ARml(train_data, caret_method = "lm", max_lag = 12) -> fit
forecast(fit, h = length(test)) -> fc
autoplot(fc) + autolayer(test)
accuracy(fc, test)
Run the code above in your browser using DataLab