Missing Values
Learn how to handle missing values in time series data for accurate forecasting with TimeGPT.
TimeGPT requires time series data without missing values. While you may have multiple series starting and ending on different dates, each one must maintain a continuous data sequence.
This tutorial shows you how to handle missing values for use with TimeGPT.
For reference, this tutorial is based on the skforecast tutorial:
Forecasting Time Series with Missing Values.
Managing missing values ensures your forecasts with TimeGPT are accurate and reliable.
When dates or values are missing, fill or interpolate them according to the nature of your dataset.
1. Load Data
Load the daily bike rental counts dataset using pandas. Note that the original column names are in Spanish; you will rename them to match ds
and y
.
ds | y | |
---|---|---|
0 | 2014-06-23 | 99 |
1 | 2014-06-24 | 72 |
2 | 2014-06-25 | 119 |
3 | 2014-06-26 | 135 |
4 | 2014-06-27 | 149 |
Next, convert your dates to timestamps and assign a unique identifier (unique_id
) to handle multiple series if needed:
Reserve the last 93 days for testing:
To simulate missing data, remove specific date ranges from the training dataset:
2. Get Started with TimeGPT
Initialize a NixtlaClient
object with your Nixtla API key:
To use an Azure AI endpoint, explicitly provide the base_url
:
See the docs on Setting Up Your API Key for details.
3. Visualize Data
Plot your dataset and examine the gaps introduced above:
You can also zoom in to see gap regions more clearly:
Zero-count days often align with specific events, like COVID-19 lockdown constraints.
4. Fill Missing Values
You can use fill_gaps
from utilsforecast
to insert the missing dates:
Next, handle the newly inserted missing values by interpolation:
5. Forecast with TimeGPT
Use the timegpt-1-long-horizon
model to generate forecasts:
Visualize the forecasts against the actual test data:
Forecast comparison between the test dataset and TimeGPT predictions
Evaluate performance (MAE) using utilsforecast
:
unique_id | metric | TimeGPT | |
---|---|---|---|
0 | id1 | mae | 1824.693059 |
6. Important Considerations
• Always ensure that your data is free of missing dates and values before forecasting with TimeGPT.
• Select a gap-filling strategy based on your domain knowledge (linear interpolation, constant filling, etc.).