Irregular Timestamps
Learn how to work with both regular and irregular timestamps in TimeGPT for accurate forecasting.
Time series data often follows regular intervals. However, in certain cases—like trading days in stock markets—timestamps can be irregular. This page shows you how to work with both regular and irregular timestamps in TimeGPT.
1. Import Packages
First, import the required libraries and initialize the Nixtla client.
Initialize NixtlaClient with your API key:
2. Handling Regular Frequencies
TimeGPT automatically detects appropriate frequency for most regular intervals (e.g. daily, monthly). No manual frequency specification is needed for regular Pandas DataFrames—unless you want to override the inferred frequency.
For Polars DataFrames, specifying the frequency is mandatory. Here’s an example using Polars:
When you run the code, you’ll see logs indicating each step of the process in the console:
Plot the forecast results:
Air Passengers Forecast
3. Handling Irregular Frequencies
Irregular frequencies mean timestamps are not equally spaced, such as stock market trading days. TimeGPT handles irregular frequencies but requires an explicit frequency specification. Make sure you have no missing data. If data is missing, see the missing dates tutorial.
4. Summary
Key Takeaways
- TimeGPT infers regular frequencies automatically.
- Polars DataFrames require manual frequency specification.
- Custom frequencies allow forecasts only on valid (or desired) dates.
- Ensure no missing data for irregular timestamps.
You can now forecast time series that do not align to standard daily, monthly, or hourly intervals. By explicitly specifying your own custom frequencies, TimeGPT maintains accuracy even in irregular data scenarios.
For more details on handling missing data, visit the Missing Dates Tutorial.