What are Prediction Intervals?

Prediction intervals measure the uncertainty around forecasted values. By specifying a confidence level, you can visualize the range in which future observations are expected to fall.

Key Parameter: level

The level parameter accepts values between 0 and 100 (including decimals). For example, [80] represents an 80% confidence interval.

Overview

Use the forecast method’s level parameter to generate prediction intervals. This helps quantify the uncertainty around your forecasts.

1

Step 1: Import Dependencies

Import Dependencies
import pandas as pd
from nixtla import NixtlaClient
2

Step 2: Initialize NixtlaClient

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

(Optional) Use an Azure AI Endpoint

4

Step 3: Load Dataset

Load Dataset
df = pd.read_csv(
    "https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv"
)
5

Step 4: Generate Forecast with an 80% Interval

Generate 80% Interval Forecast
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    time_col='timestamp',
    target_col='value',
    level=[80]
)
6

Step 5: Plot Predictions and Intervals

Plot Forecast and Intervals
nixtla_client.plot(
    df=df,
    forecasts_df=forecast_df,
    time_col='timestamp',
    target_col='value',
    level=[80]
)

Logs indicate the validation and preprocessing steps, along with the inferred data frequency:

Forecast with an 80% Prediction Interval

For more information on uncertainty estimation, refer to the tutorials about quantile forecasts and prediction intervals.