Conformalized Forecasting using Machine Leaning models

mlf(
  y,
  h = 5,
  level = 95,
  lags = 15L,
  fit_func = ahead::ridge,
  predict_func = predict,
  coeffs = NULL,
  type_pi = c("kde", "surrogate", "bootstrap"),
  B = 250L,
  agg = c("mean", "median"),
  seed = 123,
  ...
)

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)

coeffs

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

type_pi

Type of prediction interval

B

Number of bootstrap replications or number of simulations

agg

"mean" or "median" (aggregation method)

...

additional parameters passed to the fitting function fit_func

Examples


res <- ahead::mlf(USAccDeaths, h=10L, lags=15L, type_pi="surrogate", B=250L)
plot(res)


res <- ahead::mlf(USAccDeaths, fit_func = glmnet::cv.glmnet, h=15L, lags=15L, 
type_pi="kde", B=250L) 
#> Warning: Option grouped=FALSE enforced in cv.glmnet, since < 3 observations per fold
#> Warning: Option grouped=FALSE enforced in cv.glmnet, since < 3 observations per fold
plot(res)


(res <- ahead::mlf(USAccDeaths, fit_func = e1071::svm, h=15L, lags=15L, 
type_pi="kde", B=250L)) 
#>          Point Forecast    Lo 95     Hi 95
#> Jan 1979       8199.674 6473.090  9969.367
#> Feb 1979       7729.387 6114.349  9632.456
#> Mar 1979       7792.193 6132.693  9821.170
#> Apr 1979       8192.800 6448.504 10084.277
#> May 1979       8829.029 7247.419 10818.663
#> Jun 1979       9401.282 7554.712 11260.581
#> Jul 1979       9962.968 8359.314 11814.882
#> Aug 1979       9748.157 8005.109 11577.599
#> Sep 1979       9388.119 7739.654 11305.827
#> Oct 1979       9136.904 7200.491 10908.398
#> Nov 1979       8821.085 7242.572 10445.693
#> Dec 1979       9068.206 6963.608 11055.792
#> Jan 1980       8340.255 6799.574 10256.971
#> Feb 1980       8023.531 6147.344  9887.678
#> Mar 1980       7968.533 6055.050  9964.622
plot(res)