Forecasting using Machine Leaning models

ml_forecast(
  y,
  h,
  level = 95,
  lags = 1,
  fit_func = ahead::ridge,
  predict_func = predict,
  xreg = NULL,
  coeffs = NULL,
  ...
)

Arguments

y

A numeric vector or time series of class ts

h

Forecasting horizon

level

Confidence level for prediction intervals

lags

Number of lags of the input time series considered in the regression

fit_func

Fitting function (Statistical/ML model). Default is Ridge regression.

predict_func

Prediction function (Statistical/ML model)

xreg

External regressor variable

coeffs

Coefficients of the fitted model. If provided, a linear combination with the coefficients is used to compute the prediction.

...

additional parameters passed to the fitting function fit_func

Value

An object of class 'forecast'

Examples


if (FALSE) { # \dontrun{
plot(ahead::ml_forecast(AirPassengers, h=20L))

plot(ahead::ml_forecast(AirPassengers, h=25L, lags=20L, fit_func=glmnet::cv.glmnet)) 

res <- ahead::ml_forecast(USAccDeaths, h=15L, lags=15L)
plot(res)

res <- ahead::ml_forecast(USAccDeaths, fit_func = glmnet::cv.glmnet, h=15L, lags=15L) 
plot(res)

res <- ahead::ml_forecast(USAccDeaths, fit_func = e1071::svm, h=15L, lags=15L) 
plot(res)

res <- ahead::ml_forecast(mdeaths, h=15L, lags=15L)
plot(res)

res <- ahead::ml_forecast(fdeaths, fit_func = glmnet::cv.glmnet, h=15L, lags=25L) 
plot(res)

res <- ahead::ml_forecast(fdeaths, fit_func = randomForest::randomForest, h=15L, lags=15L) 
plot(res)
} # }