Forecasting intermittent demand (demand that contains many zero values) can be challenging, especially when performance and accuracy are paramount. In this tutorial, we demonstrate how to handle intermittent demand data using TimeGPT. We use a subset of the M5 dataset that captures food item sales in a California store, including exogenous variables like selling price and daily events.
TimeGPT delivers:
An impressive Mean Absolute Error (MAE) of 0.49, a 14% improvement over the best statistical model specifically designed for intermittent series.
Quick inference times (approximately 6.8 seconds for prediction), slightly slower (~1 second) than statistical models but highly accurate.
# Reserve the last 28 days for testingtest_df = df_transformed.groupby('unique_id').tail(28)input_df = df_transformed.drop(test_df.index).reset_index(drop=True)
4
Step 4: Forecast with TimeGPT
Forecast Execution
Copy
Ask AI
start = time.time()fcst_df = nixtla_client.forecast( df=input_df, h=28, level=[80], finetune_steps=10, finetune_loss='mae', model='timegpt-1-long-horizon', time_col='ds', target_col='y', id_col='unique_id')timegpt_duration = time.time() - startprint(f"Time (TimeGPT): {timegpt_duration}")# Inverse transform predictionscols = [col for col in fcst_df.columns if col not in ['ds', 'unique_id']]fcst_df[cols] = np.exp(fcst_df[cols]) - 1
Available Models in Azure AI
To use Azure AI directly, set model="azureai".
Public API models include timegpt-1 and timegpt-1-long-horizon.
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.