Our time series model offers a powerful feature that allows you to retrieve historical forecasts alongside prospective predictions. You can access this functionality by using the forecast method and setting add_history=True.

Historical forecasts can help you understand how well the model has performed in the past. This view provides insight into the model’s predictive accuracy and any patterns in its performance.

Key Benefit

Adding historical forecasts (add_history=True) lets you compare model predictions against actual data, helping to identify trends.

When to Use Historical Forecasts

Useful for performance evaluation, model reliability checks, and building trust in the predictions.

1

1. Import Required Packages

Import Packages and Initialize NixtlaClient
import pandas as pd
from nixtla import NixtlaClient
Initialize NixtlaClient with API Key
nixtla_client = NixtlaClient(
    # Defaults to os.environ.get("NIXTLA_API_KEY")
    api_key='my_api_key_provided_by_nixtla'
)

Use an Azure AI endpoint
If you want to use an Azure AI endpoint, set the base_url argument:

Initialize NixtlaClient with Azure AI Endpoint
nixtla_client = NixtlaClient(
    base_url="your azure ai endpoint",
    api_key="your api_key"
)
2

2. Load the Dataset

Plot Initial Time Series
nixtla_client.plot(df, time_col='timestamp', target_col='value')

Time Series Plot

3

3. Generate Historical Forecast

Inspection

Review the first rows of the historical predictions:

Inspect Historical Predictions
timegpt_fcst_with_history_df.head()
timestampTimeGPT
01951-01-01135.483673
11951-02-01144.442398
21951-03-01157.191910
31951-04-01148.769363
41951-05-01140.472946

Compare Observed & Predicted

Plot the observed time series against both historical and future predictions for a consolidated view:

Plot Observed vs Predictions
nixtla_client.plot(df, timegpt_fcst_with_history_df, time_col='timestamp', target_col='value')

Historical and Future Predictions Plot

Note that initial values of the dataset are not included in the historical forecasts. The model needs a certain number of observations before it can begin generating historical predictions. These early points serve as input data and cannot themselves be forecasted.