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
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.
Like these articles?
👉 Register to stay in the know 👈
on new cutting-edge R software like
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.
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
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.
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
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:
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,
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
- 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
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
modeltime plus the most powerful time series forecasting techniques available like GluonTS Deep Learning. Become the times series domain expert in your organization.
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.
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:
Modeltime Ecosystem Roadmap on GitHub - See the past development and future trajectory. Did we miss something? Make a suggestion.
Business Science data science blog - I announce all Modeltime Software happenings
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.
Alberto González Almuiña has helped BIG TIME with development of
modeltime.h2ocontributing the initial software design.
Shafiullah Qureshi helped with providing guiding examples and Modeltime H2O testing
Vidar Ingason helped with Modeltime H2O testing
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.