Irregular timestamps
- For pandas dataframes TimeGPT will try to infer the frequency of your timestamps. If you don’t want TimeGPT to infer the frequency for you, you have to set the
freq
argument to a valid pandas frequency string, e.g. ‘MS’, ‘YE’. - For polars dataframes you have to set the
freq
argument to a valid polars offset, e.g. ‘1d’, ‘2w’.
If your data has missing timestamps please refer to our tutorial on missing values.
import pandas as pd
from nixtla import NixtlaClient
from utilsforecast.data import generate_series
nixtla_client = NixtlaClient(
# defaults to os.environ.get("NIXTLA_API_KEY")
api_key = 'my_api_key_provided_by_nixtla'
)
Use an Azure AI endpoint
To use an Azure AI endpoint, remember to set also the
base_url
argument:
nixtla_client = NixtlaClient(base_url="you azure ai endpoint", api_key="your api_key")
# Read data
# Dates for the weekends are missing
df = pd.read_csv(
'https://datasets-nixtla.s3.amazonaws.com/pltr.csv',
usecols=['date', 'Close'],
)
# Forecast
# the frequency is inferred as B, as only business days are represented in the dataset
forecast_df = nixtla_client.forecast(
df=df,
h=5,
time_col='date',
target_col='Close',
)
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Inferred freq: B
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Restricting input...
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...
# manually set the frequency
forecast_df2 = nixtla_client.forecast(
df=df,
freq='B',
h=5,
time_col='date',
target_col='Close',
)
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Restricting input...
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...
pd.testing.assert_frame_equal(forecast_df, forecast_df2)
Available models in Azure AI
If you are using an Azure AI endpoint, please be sure to set
model="azureai"
:
nixtla_client.forecast(..., model="azureai")
For the public API, we support two models:
timegpt-1
andtimegpt-1-long-horizon
.By default,
timegpt-1
is used. Please see this tutorial on how and when to usetimegpt-1-long-horizon
.
Updated about 2 months ago