Skip to main content

Introduction

Intermittent demand occurs when products or services have irregular purchase patterns with frequent zero-value periods. This is common in retail, spare parts inventory, and specialty products where demand is irregular rather than continuous. Forecasting these patterns accurately is essential for optimizing stock levels, reducing costs, and preventing stockouts. TimeGPT excels at intermittent demand forecasting by capturing complex patterns that traditional statistical methods miss. This tutorial demonstrates TimeGPT’s capabilities using the M5 dataset of food sales, including exogenous variables like pricing and promotional events that influence purchasing behavior.

What You’ll Learn

  • How to prepare and analyze intermittent demand data
  • How to leverage exogenous variables for better predictions
  • How to use log transforms to ensure realistic forecasts
  • How TimeGPT compares to specialized intermittent demand models
The methods shown here apply broadly to inventory management and retail forecasting challenges. For getting started with TimeGPT, see our quickstart guide.

How to Use TimeGPT to Forecast Intermittent Demand

Open In Colab

Step 1: Environment Setup

Start by importing the required packages for this tutorial and create an instance of NixtlaClient.

Step 2: Load and Visualize the Dataset

Load the dataset from the M5 dataset and convert the ds column to a datetime object:
Visualize the dataset using the plot method:
Dataset Plot

Figure 1: Visualization of intermittent demand data

In the figure above, we can see the intermittent nature of this dataset, with many periods with zero demand. Now, let’s use TimeGPT to forecast the demand of each product.

Step 3: Transform the Data

To avoid getting negative predictions coming from the model, we use a log transformation on the data. That way, the model will be forced to predict only positive values. Note that due to the presence of zeros in our dataset, we add one to all points before taking the log.
Now, let’s keep the last 28 time steps for the test set and use the rest as input to the model.

Step 4: Forecast with TimeGPT

Forecast with TimeGPT using the forecast method:
Great! We now have predictions. However, those predictions are transformed, so we need to inverse the transformation to get back to the original scale. Therefore, we take the exponential and subtract one from each data point.

Step 5: Evaluate the Forecasts

Before measuring the performance metric, let’s plot the predictions against the actual values.
Predictions vs Actual Values

Figure 2: Visualization of the predictions against the actual values

Finally, we can measure the mean absolute error (MAE) of the model. Learn more about evaluation metrics in our documentation.

Step 6: Compare with Statistical Models

The library statsforecast by Nixtla provides a suite of statistical models specifically built for intermittent forecasting, such as Croston, IMAPA and TSB. Let’s use these models and see how they perform against TimeGPT.
Then, we can fit the models on our data.
Again, we need to inverse the transformation. Remember that the training data was previously transformed using the log function.
Now, let’s combine the predictions from all methods and see which performs best.
In the table above, we can see that TimeGPT achieves the lowest MAE, achieving a 12.8% improvement over the best performing statistical model. These results demonstrate TimeGPT’s strong performance without additional features. We can further improve accuracy by incorporating exogenous variables, a capability TimeGPT supports but traditional statistical models do not.

Step 7: Use Exogenous Variables

To forecast with exogenous variables, we need to specify their future values over the forecast horizon. Therefore, let’s simply take the types of events, as those dates are known in advance. You can also explore using date features and holidays as exogenous variables.
Then, we simply call the forecast method and pass the futr_exog_df in the X_df parameter.
Great! Remember that the predictions are transformed, so we have to inverse the transformation again.
Finally, let’s evaluate the performance of TimeGPT with exogenous features.
From the table above, we can see that using exogenous features improved the performance of TimeGPT. Now, it represents a 14% improvement over the best statistical model.

Conclusion

TimeGPT provides a robust solution for forecasting intermittent demand:
  • ~14% MAE improvement over specialized models
  • Supports exogenous features for enhanced accuracy
By leveraging TimeGPT and combining both internal series patterns and external factors, organizations can achieve more reliable forecasts even for challenging intermittent demands.

Next Steps