Learn how to validate time series models with rolling-window cross-validation
Rolling-window cross-validation conceptually splits your dataset into multiple training and validation sets over time.
cross_validation
method tailored to time series forecasting. This tutorial shows how to use NixtlaClient to run cross-validation, reinforcing the reliability of your forecasting models.
ds
), a target column (e.g., y
), and, if necessary, an identifier column (e.g., unique_id
) for multiple time series.1. Import Packages and Initialize NixtlaClient
NixtlaClient
.2. Load Example Data
3. Perform Cross-Validation
Why Rolling-window Cross-validation?
Important Parameters
freq
: Frequency of your data (e.g., 'D'
for daily). If not specified, it will be inferred.
id_col
, time_col
, target_col
: Columns representing series ID, timestamps, and target values.
n_windows
: Number of separate validation windows.
step_size
: Step size between each validation window.
h
: Forecast horizon (e.g., the number of days ahead to predict).
cross_validation
on the Peyton Manning dataset:Cross-validation Log Output
TimeGPT
) aligned with historical values (y
).unique_id | ds | cutoff | y | TimeGPT |
---|---|---|---|---|
0 | 2015-12-17 | 2015-12-16 | 7.591862 | 7.939553 |
0 | 2015-12-18 | 2015-12-16 | 7.528869 | 7.887512 |
0 | 2015-12-19 | 2015-12-16 | 7.171657 | 7.766617 |
0 | 2015-12-20 | 2015-12-16 | 7.891331 | 7.931502 |
0 | 2015-12-21 | 2015-12-16 | 8.360071 | 8.312632 |
model="azureai"
in cross_validation
. Also refer to
this tutorial to explore other supported models.4. Plot Cross-Validation Results
An example visualization of predicted vs. actual values in the Peyton Manning dataset.
5. Use Prediction Intervals, Exogenous Variables, and Model Variations
Features to Enhance Your Model
level=[80, 90]
to compute confidence intervals.
date_features=['month']
, or provide your own dynamic exogenous variables.
model='timegpt-1-long-horizon'
(or other Nixtla-supported models) for specialized tasks like long-horizon forecasts.
Example Usage
unique_id | ds | cutoff | y | TimeGPT | TimeGPT-lo-90 | TimeGPT-hi-90 | TimeGPT-lo-80 | TimeGPT-hi-80 |
---|---|---|---|---|---|---|---|---|
0 | 2015-12-17 | 2015-12-16 | 7.591862 | 7.939553 | 7.112531 | 8.730458 | 7.316611 | 8.562029 |
cross_validation
in Nixtla’s TimeGPT ensures predictions are accurate and reliable. Incorporating confidence intervals, exogenous variables, and different model variants can further enhance your forecasts, giving you robust insights for real-world applications.