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
How to Use TimeGPT to Forecast Intermittent Demand
Step 1: Environment Setup
Start by importing the required packages for this tutorial and create an instance ofNixtlaClient.
Step 2: Load and Visualize the Dataset
Load the dataset from the M5 dataset and convert theds column to a datetime object:
Visualize the dataset using the
plot method:

Figure 1: Visualization of intermittent demand data
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.Step 4: Forecast with TimeGPT
Forecast with TimeGPT using theforecast method:
Step 5: Evaluate the Forecasts
Before measuring the performance metric, let’s plot the predictions against the actual values.
Figure 2: Visualization of the predictions against the actual values
Step 6: Compare with Statistical Models
The librarystatsforecast 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.
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.
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
Next Steps
- Explore other use cases with TimeGPT
- Learn about probabilistic forecasting with prediction intervals
- Scale your forecasts with distributed computing
- Fine-tune models with custom loss functions