要使用 TimeGPT 进行预测,请调用 forecast 方法。传入您的 DataFrame 并指定目标列和时间列的名称。然后使用 plot 方法绘制预测结果。您可以此处阅读有关数据要求的更多信息。

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 the data
df = pd.read_csv("https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv")

# Forecast
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    time_col='timestamp',
    target_col="value"
)

# Plot predictions
nixtla_client.plot(
    df=df, 
    forecasts_df=forecast_df, 
    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:Restricting input...
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...

📘 Azure AI 中的可用模型

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

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

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

默认情况下,使用 timegpt-1。有关使用 timegpt-1-long-horizon 的详细信息,请参阅本教程