我们可以通过指定 finetune_steps 参数来微调 TimeGPT。

import pandas as pd
from nixtla import NixtlaClient
nixtla_client = NixtlaClient(
    # defaults to os.environ.get("NIXTLA_API_KEY")
    api_key = 'my_api_key_provided_by_nixtla'
)

👍 使用 Azure AI 端点

要使用 Azure AI 端点,请记住同时设置 base_url 参数

nixtla_client = NixtlaClient(base_url="you azure ai endpoint", api_key="your api_key")

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

# Forecast with fine-tuning.
# Here, we fine-tune for 5 steps
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    finetune_steps=5,
    time_col='timestamp',
    target_col="value"
)

📘 Azure AI 中可用的模型

如果您使用的是 Azure AI 端点,请务必设置 model="azureai"

nixtla_client.forecast(..., model="azureai")

对于公共 API,我们支持两种模型:timegpt-1timegpt-1-long-horizon

默认情况下,使用 timegpt-1。请参阅本教程,了解如何以及何时使用 timegpt-1-long-horizon

默认情况下,仅应用少量微调 (finetune_depth=1)。我们可以通过增加 finetune_depth 参数来增强微调强度。请注意,增加 finetune_depthfinetune_steps 会增加生成预测的实际耗时。

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

# Forecast with fine-tuning.
# Here, we fine-tune for 5 steps
# and we finetune more than just the last layer
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    finetune_steps=5,
    finetune_depth=2,
    time_col='timestamp',
    target_col="value"
)

有关微调的更多信息,请阅读我们的微调教程