Overview

3 Forecasting with TimeGPT

This chapter introduces TimeGPT as a practical, foundation-model approach to time series forecasting, contrasting it with the challenges of training bespoke models from scratch. Using a multi-store Walmart weekly sales dataset with rich exogenous drivers as a running example, it frames how a single, pretrained generative model can forecast diverse series, quantify uncertainty, and even repurpose its forecasts for anomaly detection. The narrative emphasizes hands-on use—zero-shot forecasting, fine-tuning, leveraging external variables, robust evaluation, and long-horizon scenarios—while highlighting when these capabilities help and where they may fall short.

TimeGPT is a full encoder–decoder Transformer, pretrained on a vast, multi-domain corpus to learn varied temporal patterns and generalize across frequencies and scales. It is probabilistic, producing prediction intervals via conformal prediction adapted to time series, and it natively accepts exogenous features—provided both their past and future values are available. Accessed through a simple API client, it delivers strong zero-shot baselines, and can be specialized with lightweight fine-tuning by setting the number of steps, the optimization loss, and the breadth of parameters to update, which often yields measurable gains. For extended horizons, a variant tuned for long-range dependencies improves accuracy over the base model.

The chapter also covers practicalities: preparing data with the expected identifiers and timestamps, building future exogenous inputs, and interpreting forecasts with Shapley-based feature contributions. It recommends cross-validation with non-overlapping windows to obtain reliable metrics, and shows how anomaly detection is performed by labeling points that fall outside high-confidence historical forecast intervals—while noting limitations at the series start and the precision–recall trade-off controlled by interval width. Overall, TimeGPT streamlines modern forecasting through an API-first workflow that combines rapid zero-shot use, targeted fine-tuning, principled uncertainty, explainability, and basic anomaly detection across a wide range of series and horizons.

Overall architecture of the Transformer model. Notice how the output of the decoder is sent back as an input to continue generating the output sequence.
Different temporal patterns appear with different domains. On the left, hourly traffic data shows a daily and weekly seasonality. On the right, daily temperature data exhibits a yearly seasonality.
Rolling a die is an example of exchangeability. Here the die is rolled four times. Rearranging the obtained values gives a sequence that is equally likely as the original one.
Overview of conformal prediction for time series data. Historical predictions are used to calculate conformity scores. These scores are then used to generate a range of possible values for each point forecast. From that range of possible values, we calculate the quantiles corresponding to a user-specified confidence level.
Guiding example to build conformal prediction intervals. Here, we suppose we run cross-validation using two windows and a horizon of three time steps. For each window, we have the actual and predicted values. The forecasts represent predictions for the future, for which we do not know the actual values. The goal is to build the conformal prediction interval for each point forecast.
Adding conformity scores for each window. Here, the conformity score is calculated as the absolute difference between the actual and predicted value.
Calculating the range of possible values for the first point forecast. Notice that we simply add and subtract all conformity scores from the forecast to get its range of possible values. The same step is repeated for each point forecast.
General workflow of TimeGPT. After initializing the client and loading the data, we then use the client for anomaly detection, forecasting and cross-validation.
Plotting the weekly sales of four Walmart stores. While each store shares a similar general pattern, the granular behavior is unique for each store.
Plotting the predictions obtained with TimeGPT. Notice how the prediction intervals are different for each series.
Average Shapley values of exogenous variables for predicting the weekly sales of a Walmart store. On average, the CPI feature increases the base forecast by 46271 and fuel price increases it by 11329 on average. Holidays have no impact on the final value.
Waterfall plot for the prediction on 2012-09-07. The base value of 1528469.8 is the forecast if no exogenous features were used. Then, the value of fuel price at that date decreases the prediction by 6043.04. However, the value of CPI then increases it by 40984.73, which results in a final prediction of 1563411.49.
Plotting the performance of zero-shot forecasting, fine-tuning, and fine-tuning with exogenous variables. Lowest values indicate the best performance. Here, fine-tuning more parameters, without using features, results in the best performance.
Illustrating the behavior of cross-validation with TimeGPT. A fold designates one round of cross-validation. By default, non-overlapping windows are used.
Visualizing cross-validation in TimeGPT. Each vertical line indicates the start of a cross-validation window or fold. There are four of them, which corresponds to the number of windows set in listing 3.19. In between each vertical line, we see the predictions being made at each fold. The prediction line (dashed) is hard to see as it mostly overlaps the actual data.
Comparing the performance of the base model and timegpt-1-long-horizon. Lower values are better. Here, when forecasting on a long horizon, using the adapted model generated better results.
Daily number of taxi customers in New York city, from July 2014 to the end of January 2015. The four dots represent the anomalous points.
Plotting the anomalies detected by TimeGPT. The dotted line shows the historical forecasts. The shaded area represents the 99% prediction interval. If a point falls outside the interval, it is labelled as an anomaly. Diamonds indicate predicted anomalies while dots represent the actual anomalies not detected by TimeGPT. If a detected and an actual anomaly coincides, meaning that the model correctly identified the anomaly, then only a diamond is shown.
Comparing the performance of anomaly detection using different prediction intervals. Higher values are better. The 99% prediction interval results in more balanced results, as the F1-score is higher than when we reduce the prediction interval.

Summary

  • TimeGPT is a proprietary model developed by Nixtla. It is a pretrained generative Transformer trained on 100 billion data points.
  • TimeGPT is accessed via API and requires an access token.
  • With TimeGPT, we can perform zero-shot forecasting, forecast multiple series concurrently, fine-tune the model, include exogenous variables, do cross-validation and detect anomalies.
  • When fine-tuning, we can specify the number of steps and the loss function to be used.
  • When forecasting on a long horizon, remember to use the model timegpt-1-long-horizon.
  • When doing anomaly detection, a smaller level, or a smaller prediction interval, results in more anomalies being detected, so the recall increases and the precision decreases. The opposite is true when the prediction interval is large.

FAQ

What is TimeGPT and is it open-source?TimeGPT is a full encoder–decoder Transformer foundation model for time series, pretrained on a massive, multi-domain corpus. It is a proprietary product by Nixtla (not open-source). You access it via API (Python nixtla, R nixtlar, cURL, etc.), via Azure AI, or self-hosted enterprise options. Some architectural and training details are undisclosed.
How does a Transformer act as a generative model for forecasting?The encoder learns relationships in the historical input sequence. The decoder then generates future values autoregressively: each newly predicted step is fed back into the decoder to produce the next step. This feedback loop allows generation of sequences of arbitrary length (the forecast horizon).
What exactly does TimeGPT model, and what does that imply for exogenous features?TimeGPT estimates the conditional distribution of future target values given past target values and both past and future exogenous features. Practically, this means you must provide future values of any exogenous variables you want the model to use (for the whole forecast horizon). For dynamic features (like temperature or fuel price), you must forecast them first; fixed or known-in-advance features (like holidays) can be supplied directly.
How does TimeGPT produce prediction intervals?TimeGPT uses conformal prediction. In time series, it adapts the procedure by: - Generating historical forecasts (e.g., via cross-validation) for which actuals are known. - Computing conformity scores (absolute residuals) from those forecasts. - Building a distribution of possible values around each point forecast by adding/subtracting the scores. - Taking quantiles that match the requested coverage (e.g., 10th/90th for an 80% interval). This yields model-agnostic, distribution-free intervals with specified coverage.
How do I access the API and what data format does TimeGPT expect?- Get an API key at https://dashboard.nixtla.io (free trial; free plan with limited calls thereafter).
- Use the nixtla client and pass a DataFrame with at least: an identifier column, a timestamp column, and a target column. Defaults are unique_id, ds, y, but you can map yours via id_col, time_col, target_col.
- The model infers frequency from the timestamp and forecasts each series in parallel (it is not multivariate across series by default). Zero-shot forecasting (no prior training on your data) works out-of-the-box.
How do I fine-tune TimeGPT, and what are the trade-offs?Enable fine-tuning directly in forecast calls: - finetune_steps: number of parameter-update steps (start small; more steps increase latency and risk overfitting). - finetune_loss: one of ['mae','mse','rmse','mape','smape'] to align training with your metric preference. - finetune_depth: 1–5, controlling how many parameters are tuned (higher is deeper/more compute and higher overfitting risk). Fine-tuning can improve accuracy, but monitor a validation set and increment gradually.
How do I include exogenous variables, and can I explain their impact?- Provide a DataFrame with future values of the features for the whole horizon via X_df. You must forecast any dynamic features first.
- Set feature_contributions=True to retrieve Shapley values that attribute how each feature moves the forecast away from the base prediction (no-features case). Shapley values are additive: base_value + sum(contributions) = final forecast.
- Note: Errors in feature forecasts can propagate and degrade target forecasts.
How should I evaluate TimeGPT with limited test data?Use the built-in cross_validation method: - n_windows creates multiple non-overlapping evaluation folds at a fixed horizon h. - After each fold, the input window is advanced by h steps (mimicking production roll-forward). - You can still specify fine-tuning arguments; fine-tuning happens once before the first cutoff and the model is then fixed. Evaluate with metrics such as MAE and sMAPE over all folds for a more reliable estimate.
Does TimeGPT support long-horizon forecasting?Yes. Use model='timegpt-1-long-horizon' for horizons longer than a seasonal period (e.g., >52 weeks for yearly seasonality). It shares the base architecture but is pretrained to better capture information useful far into the future, and can outperform the base model on long horizons.
How does anomaly detection work in TimeGPT, and what are its limitations?TimeGPT repurposes forecasting: it generates historical forecasts with a wide (e.g., 99%) prediction interval and flags points outside the interval as anomalies. Limitations and tips: - Early data points (used as initial input) cannot be flagged. - The level parameter controls the interval width: lowering it typically increases recall (more anomalies found) but reduces precision (more false positives). Choose based on your tolerance for misses vs false alarms.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free