Introducing Modeltime H2O: Automatic Forecasting with H2O AutoML
Written by Matt Dancho and Alberto GonzƔlez AlmuiƱa
Iām beyond excited to introduce modeltime.h2o
, the time series forecasting package that integrates H2O AutoML (Automatic Machine Learning) as a Modeltime Forecasting Backend. This tutorial (view the original article here) introduces our new R Package, Modeltime H2O.
- Weāll quickly introduce you to the growing modeltime ecosystem.
- Then, weāll forecast with H2O AutoML using the
modeltime.h2o
backend
If you like what you see, I have an Advanced Time Series Course where you will learn the foundations of the growing Modeltime Ecosystem.
Time Series Forecasting Article Guide:
This article is part of a series of software announcements on the Modeltime Forecasting Ecosystem.
-
(Start Here) Modeltime: Tidy Time Series Forecasting using Tidymodels
-
Modeltime H2O: Forecasting with H2O AutoML
-
Modeltime Ensemble: Time Series Forecast Stacking
-
Modeltime Recursive: Tidy Autoregressive Forecasting
-
Hyperparameter Tuning Forecasts in Parallel with Modeltime
-
Time Series Forecasting Course: Now Available
Like these articles?
š Register to stay in the know
š
on new cutting-edge R software like modeltime
.
Meet the Modeltime Ecosystem
A growing ecosystem for tidymodels forecasting
Modeltime H2O is part of a growing ecosystem of Modeltime forecasting packages. The main purpose of the Modeltime Ecosystem is to develop scalable forecasting systems.
Modeltime H2O
The H2O AutoML backend for Modeltime
Modeltime H2O provides an H2O backend to the Modeltime Forecasting Ecosystem. The main algorithm is H2O AutoML, an automatic machine learning library that is built for speed and scale.
This forecast was created with H2O AutoML. Weāll make this forecast in our short tutorial.
Getting Started with Modeltime H2O
Forecasting with modeltime.h2o
made easy! This short tutorial shows how you can use:
-
H2O AutoML for forecasting implemented via automl_reg()
. This function trains and cross-validates multiple machine learning and deep learning models (XGBoost GBM, GLMs, Random Forest, GBMsā¦) and then trains two Stacked Ensembled models, one of all the models, and one of only the best models of each kind. Finally, the best model is selected based on a stopping metric. And we take care of all this for you!
-
Save & Load Models functionality to ensure the persistence of your models.
Get the Cheat Sheet
As you go through this tutorial, it may help to use the Ultimate R Cheat Sheet. Page 3 Covers the Modeltime Forecasting Ecosystem with links to key documentation.
Forecasting Ecosystem Links (Ultimate R Cheat Sheet)
Libraries
The modeltime.h2o
package is now on CRAN:
Load the following libraries:
Collect data and split into training and test sets
Next, we load the walmart_sales_weekly data containing 7 time series and visualize them using the timetk::plot_time_series()
function.
Then, we separate the data with the initial_time_split()
function and generate a training dataset and a test one.
Model specification, training and prediction
In order to correctly use modeltime.h2o
, it is necessary to connect to an H2O cluster through the h2o.init()
function. You can find more information on how to set up the cluster by typing ?h2o.init
or by visiting the official site.
Now comes the fun part! We define our model specification with the automl_reg()
function and pass the arguments through the engine:
Next, letās train the model!
We can check out the trained H2O AutoML model.
Finally, we predict on the test dataset:
Modeltime Workflow
Once we have our fitted model, we can follow the Modeltime Workflow:
-
Add fitted models to a Model Table.
-
Calibrate the models to a testing set.
-
Perform Testing Set Forecast Assessment & Accuracy Evaluation.
-
Refit the models to Full Dataset & Forecast Forward
Add fitted models to a Model Table
First, we create the model table:
Calibrate & Testing Set Forecast & Accuracy Evaluation
Next, we calibrate to the testing set and visualize the forecasts:
Refit to Full Dataset & Forecast Forward
Before using refit on our dataset, letās prepare our data. We create data_prepared_tbl
which represents the complete dataset (the union of train and test) with the variables created with the recipe named recipe_spec. Subsequently, we create the dataset future_prepared_tbl
that represents the dataset with the future data to one year and the required variables.
Finally, we use modeltime_refit()
to re-train our model on the entire dataset. This is a best-practice for improving forecast results.
Letās visualize the final forecast
We can quickly visualize the final forecast with modeltime_forecast()
and itās plotting utility function, plot_modeltime_forecast()
.
We can likely do better than this if we train longer but really good for a quick example!
Saving and Loading Models
H2O models will need to āserializedā (a fancy word for saved to a directory that contains the recipe for recreating the models). To save the models, use save_h2o_model()
.
- Provide a directory where you want to save the model.
- This saves the model file in the directory.
You can reload the model into R using load_h2o_model()
.
It gets better
Youāve just scratched the surface, hereās whatās comingā¦
The Modeltime Ecosystem functionality is much more feature-rich than what weāve covered here (I couldnāt possibly cover everything in this post). š
Hereās what I didnāt cover:
-
Feature Engineering: We can make this forecast much more accurate by including features from competition-winning strategies
-
Ensemble Modeling: We can stack H2O Models with other models not included in H2O like GluonTS Deep Learning.
-
Deep Learning: We can use GluonTS Deep Learning for developing high-performance, scalable forecasts.
So how are you ever going to learn time series analysis and forecasting?
Youāre probably thinking:
- Thereās so much to learn
- My time is precious
- Iāll never learn time series
I have good news that will put those doubts behind you.
You can learn time series analysis and forecasting in hours with my state-of-the-art time series forecasting course. š
High-Performance Time Series Course
Become the times series expert in your organization.
My High-Performance Time Series Forecasting in R course is available now. Youāll learn timetk
and modeltime
plus the most powerful time series forecasting techniques available like GluonTS Deep Learning. Become the times series domain expert in your organization.
š High-Performance Time Series Course.
You will learn:
- Time Series Foundations - Visualization, Preprocessing, Noise Reduction, & Anomaly Detection
- Feature Engineering using lagged variables & external regressors
- Hyperparameter Tuning - For both sequential and non-sequential models
- Time Series Cross-Validation (TSCV)
- Ensembling Multiple Machine Learning & Univariate Modeling Techniques (Competition Winner)
- Deep Learning with GluonTS (Competition Winner)
- and more.
Unlock the High-Performance Time Series Course
Project Roadmap, Future Work, and Contributing to Modeltime
Modeltime is a growing ecosystem of packages that work together for forecasting and time series analysis. Here are several useful links:
Acknowledgements
Iād like to acknowledge several Business Science University students that are part of the BSU Modeltime Dev Team that have helped develop modeltime.h2o
. There efforts are truly appreciated.
Have questions about Modeltime H2O?
Make a comment in the chat below. š
And, if you plan on using modeltime.h2o
for your business, itās a no-brainer - Join my Time Series Course.