Forecasting Energy Demand
Learn how TimeGPT accurately predicts electricity consumption patterns
TimeGPT delivers highly accurate, fast forecasts. In this tutorial, you’ll learn how to reproduce a 4-day forecast for in-zone energy demand and see how TimeGPT compares to the deep-learning model N-HiTS.
This tutorial uses a subset of the PJM Hourly Energy Consumption dataset, focusing on in-zone consumption where electricity is generated and used within the same transmission zone. It contains hourly observations from October 1, 2023, to September 30, 2024, for five representative regions and is an excellent dataset to demonstrate TimeGPT’s capabilities.
With just a few lines of code, TimeGPT can achieve:
• 18.6% lower MAE compared to N-HiTS
• 31.1% lower sMAPE compared to N-HiTS
• 90% faster prediction times
Overview
Step 1: Initial Setup
Install and import required packages, then create a NixtlaClient instance to interact with TimeGPT.
If you want to connect to Azure AI instead of Nixtla’s API, specify base_url and api_key.
Step 2: Read the Data
Load the energy consumption dataset and convert datetime strings to timestamps.
Sample Data
unique_id | ds | y | |
---|---|---|---|
0 | AP-AP | 2023-10-01 04:00:00+00:00 | 4042.513 |
1 | AP-AP | 2023-10-01 05:00:00+00:00 | 3850.067 |
Plot the data series to visualize seasonal patterns.
Seasonal patterns in energy consumption.
Step 3: Forecast with TimeGPT
We’ll split our dataset into:
• A training/input set for model calibration
• A testing set (last 4 days) to validate performance
TimeGPT forecast compared to actual values.
Step 4: Evaluate TimeGPT
Compute accuracy metrics (MAE and sMAPE) for TimeGPT.
Step 5: Forecast with N-HiTS
For comparison, we train and forecast using the deep-learning model N-HiTS.
Step 6: Evaluate N-HiTS
Compute accuracy metrics (MAE and sMAPE) for N-HiTS.
Conclusion
Key Results
- TimeGPT achieves an MAE of 882.6, compared to 1084.7 from N-HiTS (18.6% improvement).
- TimeGPT’s sMAPE is 31.1% lower than N-HiTS.
- TimeGPT generates predictions in roughly 4.3 seconds, which is 90% faster than N-HiTS’s 44 seconds.
TimeGPT offers substantial benefits in accuracy and speed, making it a powerful tool for forecasting energy consumption and other time-series tasks. Experiment with the parameters to further optimize performance for your specific use case.