Prediction Intervals

In forecasting, we are often interested in the distribution of predictions rather than just point predictions, because we need a clear notion of forecast uncertainty.

Prediction intervals present a specific range within which the actual forecast values are expected to fall. For example, a 95% prediction interval means that we expect the future true value to lie within this range 95 times out of 100. Wider intervals correspond to greater uncertainty, while narrower intervals indicate higher forecast confidence.

Using TimeGPT, you can easily produce forecast distributions and derive prediction intervals at customized confidence levels. TimeGPT leverages conformal prediction to generate these intervals.

Key Concepts

Forecast Uncertainty

Prediction intervals quantify the uncertainty of a forecast. They help you assess the risk of under- or over-estimating future values.

Conformal Prediction

TimeGPT uses conformal prediction techniques to generate meaningful prediction intervals. This allows valid coverage under minimal assumptions.


1

Step 1: Import Packages

Import the required packages and initialize the Nixtla client.

Import Packages and Initialize NixtlaClient
import pandas as pd
from nixtla import NixtlaClient

nixtla_client = NixtlaClient(
    api_key='my_api_key_provided_by_nixtla'  # defaults to os.environ.get("NIXTLA_API_KEY")
)

If you want to use an Azure AI endpoint, set the base_url as shown below.

Initialize NixtlaClient with Azure AI Endpoint
nixtla_client = NixtlaClient(
    base_url="your_azure_ai_endpoint",
    api_key="your_api_key"
)
2

Step 2: Load Data

Load the dataset:

Load Air Passengers Dataset
df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv')
df.head()
timestampvalue
01949-01-01112
11949-02-01118
21949-03-01132
31949-04-01129
41949-05-01121
3

Step 3: Forecast with Prediction Intervals

To forecast using TimeGPT with customized prediction intervals, specify level as a list of desired confidence levels:

Forecast with Prediction Intervals
timegpt_fcst_pred_int_df = nixtla_client.forecast(
    df=df,
    h=12,
    level=[80, 90, 99.7],
    time_col='timestamp',
    target_col='value',
)

timegpt_fcst_pred_int_df.head()

Below is sample log output indicating the process steps (input validation, preprocessing, endpoint calls, etc.).

Forecast with predicted intervals at multiple levels

Public API Forecast Call
nixtla_client.forecast(
    df=df,
    h=12,
    level=[80, 90, 99.7],
    time_col='timestamp',
    target_col='value',
)

For the public API, supported models include:

  • timegpt-1 (default)

  • timegpt-1-long-horizon

See the Long Horizon Forecasting Tutorial.

Use wider intervals for critical predictions to handle uncertainty carefully, and narrower intervals if exact predictions are less critical.

4

Step 4: Historical Forecast


Prediction intervals are a powerful tool for understanding the uncertainty inherent in forecasting. Adjust the confidence levels (e.g., 80%, 90%, 95%, 99.7%) based on how conservative or liberal you want your estimates.