在微调时,我们可以使用 finetune_loss 参数指定要使用的损失函数。

可能的值有

  • "mae"

  • "mse"

  • "rmse"

  • "mape"

  • "smape"

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")

# Fine-tune with a specified loss function and make predictions
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    finetune_steps=5,
    finetune_loss="mae",
    time_col='timestamp',
    target_col="value"
)
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Inferred freq: MS
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...

📘 Azure AI 中可用的模型

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

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

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

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

有关指定损失函数及其如何影响模型性能的更多详细信息,请阅读我们关于使用特定损失函数进行微调的深入教程。