Bounded Forecasts
Learn how to generate forecasts with upper and lower bounds to match your business constraints.
Bounded forecasting ensures predictions remain within a meaningful range (for example, keeping forecasts positive). This tutorial shows how to generate bounded forecasts with TimeGPT by transforming data prior to forecasting.
Bounded Forecasting
Ensures forecasts remain within valid ranges (e.g., non-negative sales predictions).
Data Transformation
Methods like log-transformations help enforce bounds and improve model stability.
TimeGPT Integration
Easily apply transformations and forecast with intervals using TimeGPT’s API.
1. Import Packages
In this step, you’ll install and import the required packages. The NixtlaClient from nixtla
is used to connect with TimeGPT.
Initialize your Nixtla client with the API key:
2. Load Data
We’ll use the annual egg prices dataset from Forecasting: Principles and Practice. Because egg prices should not be negative, they are ideal for demonstrating bounded forecasts.
If you haven’t already, install pyreadr
to read R data formats.
Without showing the full table output here, the last 10 rows look like:
unique_id | ds | y | Product |
---|---|---|---|
84 | 1984-01-01 | 100.58 | eggs |
85 | 1985-01-01 | 76.84 | eggs |
86 | 1986-01-01 | 81.10 | eggs |
87 | 1987-01-01 | 69.60 | eggs |
88 | 1988-01-01 | 64.55 | eggs |
89 | 1989-01-01 | 80.36 | eggs |
90 | 1990-01-01 | 79.79 | eggs |
91 | 1991-01-01 | 74.79 | eggs |
92 | 1992-01-01 | 64.86 | eggs |
93 | 1993-01-01 | 62.27 | eggs |
Finally, let’s visualize the historical trend of egg prices during the 20th century:
Figure 1: Annual Egg Prices Trend from 1900s to 1990s
3. Generate Bounded Forecasts
Bounded forecasts can be achieved through transformations. Log-transformation is a convenient way to ensure forecasts remain positive.
First, apply a log transformation to the target variable (y
) before forecasting:
Next, create forecasts for the next 10 years with confidence intervals at 80%, 90%, and 99.5%:
Available models with Azure AI
If you’re using an Azure AI endpoint, specify model="azureai"
explicitly.
Default supported models are timegpt-1
and timegpt-1-long-horizon
.
More details in the long horizon forecasting tutorial.
Reverse the log-transformation by exponentiating the forecasted values:
Finally, plot the forecasts with intervals:
Figure 2: Bounded Forecasts with TimeGPT Using Log Transformation
First, apply a log transformation to the target variable (y
) before forecasting:
Next, create forecasts for the next 10 years with confidence intervals at 80%, 90%, and 99.5%:
Available models with Azure AI
If you’re using an Azure AI endpoint, specify model="azureai"
explicitly.
Default supported models are timegpt-1
and timegpt-1-long-horizon
.
More details in the long horizon forecasting tutorial.
Reverse the log-transformation by exponentiating the forecasted values:
Finally, plot the forecasts with intervals:
Figure 2: Bounded Forecasts with TimeGPT Using Log Transformation
If you forecast without any transformation, negative intervals or predictions may appear when actual values cannot logically be negative, as shown below:
Figure 3: Unbounded Forecast with Possible Negative Intervals
Inspecting the raw forecast values, you can confirm any negative predictions directly:
Without bounding, you may see some negative forecasts or intervals if the model extrapolates into that range.
Log-transformations are a simple and effective way to enforce non-negative predictions. This tutorial demonstrated how TimeGPT accommodates bounded forecasts to enhance forecast realism and reliability.