Overview

You can fine-tune TimeGPT forecasts by specifying the finetune_steps parameter. Fine-tuning allows you to further adjust the model to the nuances of your specific time series data, potentially improving forecast accuracy.

Fine-tuning uses additional training iterations on your own dataset. While it can improve forecast performance, it also increases the compute time needed to generate predictions.


Key Fine-tuning Concepts

finetune_steps

The number of additional training steps to run. Increasing this value can improve accuracy, but also requires more computation.

finetune_depth

The intensity or depth of the fine-tuning. By default, finetune_depth=1. Increasing it can further refine forecasts but also makes training more resource-intensive.

If you set both finetune_steps and finetune_depth too high, the training process can become very time-consuming.


Setting Up Your Environment

Before creating forecasts, you need to install and initialize the Nixtla client with your API key.

1

Install and Import Libraries

Import Libraries
import pandas as pd
from nixtla import NixtlaClient
2

Initialize the Nixtla Client

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

If you’re using an Azure AI endpoint, set the base_url parameter accordingly:

Azure AI Configuration
nixtla_client = NixtlaClient(
    base_url="your azure ai endpoint",
    api_key="your api_key"
)

Forecasting with Fine-tuning

Follow these steps to fine-tune your TimeGPT forecasts.

1

Load Data

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

Create a Forecast (Example: 5 Fine-tune Steps)

Fine-tune Forecast Example
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    finetune_steps=5,
    time_col="timestamp",
    target_col="value"
)

(Optional) Include a relevant forecast plot or diagram here.

If you are using Azure AI, specify the model name explicitly:

nixtla_client.forecast(
    df=df,
    h=12,
    finetune_steps=5,
    model="azureai",
    time_col="timestamp",
    target_col="value"
)

In the public Nixtla API, you can choose from two models:

  • timegpt-1 (default)
  • timegpt-1-long-horizon

See the long-horizon forecasting tutorial for information about when and how to use timegpt-1-long-horizon.


Advanced Fine-tuning

Increasing finetune_depth and finetune_steps will increase computation time, thus requiring more time to generate predictions.


Additional Resources

For more detailed information and advanced configurations, see the fine-tuning tutorial.