# Introducing Modeltime H2O: Automatic Forecasting with H2O AutoML

Written by Matt Dancho and Alberto González Almuiña on March 15, 2021

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:

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!

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 betterYou’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. 👇

## Advanced Time Series CourseBecome the times series expert in your organization.

My Advanced 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.

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:

# 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.