Today, give a try to Techtonique web app, a tool designed to help you make informed, data-driven decisions using Mathematics, Statistics, Machine Learning, and Data Visualization. Here is a tutorial with audio, video, code, and slides: https://moudiki2.gumroad.com/l/nrhgb. 100 API requests are now (and forever) offered to every user every month, no matter the pricing tier.
Introduction
In this post, I’ll show how to use ahead::mlf
, a function from R package ahead that does Conformalized Forecasting. ahead::mlf
uses Machine Leaning models (any of them) and time series lags in an autoregressive way, as workhorses for univariate probabilistic time series forecasting.
This function differs from ahead::dynrmf
by the fact that it doesn’t automatically select time series lags lags and by the availability of a simple stacked generalization functionality. I first discussed a stacked generalization method for forecasting in this 2018 document, at page 79.
In the context of ahead::mlf
, the algorithm described in https://www.researchgate.net/publication/379643443_Conformalized_predictive_simulations_for_univariate_time_series for time series conformal prediction is enriched: the predictions obtained on the calibration set are used as covariates for test set predictions. It’s important to choose a model that doesn’t overfit much here, as there are already a lot of information provided to the calibration set by this algorithm. I choose the Elastic Net.
What We’ll Cover
- Installing the package
- Run the examples
1 - Installing the package
options(repos = c(
techtonique = "https://r-packages.techtonique.net",
CRAN = "https://cloud.r-project.org"
))
install.packages("ahead")
install.packages("glmnet")
2 - Run the examples
At this stage, it’s worth trying out other Elastic Net implementations (e.g, just glmnet::glmnet
), in particular because, due to glmnet::cv.glmnet
’s implementation, my cross-validation is kind of backward looking. Well, use time series cross-validation to reduce forecasting volatility.
(res1 <- ahead::mlf(AirPassengers, h=25L, lags=20L, fit_func=glmnet::cv.glmnet, stack=FALSE))
(res2 <- ahead::mlf(AirPassengers, h=25L, lags=20L, fit_func=glmnet::cv.glmnet, stack=TRUE))
(res3 <- ahead::mlf(USAccDeaths, h=25L, lags=20L, fit_func=glmnet::cv.glmnet, stack=TRUE))
(res4 <- ahead::mlf(USAccDeaths, h=25L, lags=20L, fit_func=glmnet::cv.glmnet, stack=FALSE))
par(mfrow=c(1, 2))
plot(res1, main="Conformal ML without stacking")
plot(res2, main="Conformal ML with stacking")
par(mfrow=c(1, 2))
plot(res3, main="Conformal ML with stacking")
plot(res4, main="Conformal ML without stacking")
Comments powered by Talkyard.