Cross Validation
Learn how to validate your forecast models using time series cross-validation.
Cross-Validation
Cross-validation is a robust method to evaluate and improve your forecasting models. By splitting your time series into multiple windows, you can test how well your model performs on unseen data.
1. Install and Import Dependencies
Make sure you have the pandas
and nixtla
libraries installed.
2. Initialize Nixtla Client
Replace my_api_key_provided_by_nixtla
with the API key you received from Nixtla.
To use an Azure AI endpoint, add the base_url
argument.
3. Read and Prepare Data
In this example, we are using the airplane passengers dataset. You can replace the URL with your own dataset.
4. Perform Cross-Validation
Specify the number of windows with the n_windows
argument. Each window will be used to generate forecasts and evaluate performance.
If you’re using an Azure AI endpoint for forecasting, define the model explicitly by setting model="azureai"
in the forecast
method:
timegpt-1
This is the default model in the public API. It provides reliable short- to medium-range forecasts.
timegpt-1-long-horizon
Designed for extended-range forecasts. Refer to the long-horizon forecasting tutorial for more details.
For more guidance and examples, consult our cross-validation tutorial.