Add date features

If your dataset lacks exogenous variables, add date features to inform the model for anomaly detection. Use the date_features argument. Set it to True to extract all possible features, or pass a list of specific features to include.

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

👍

Use an Azure AI endpoint

To use an Azure AI endpoint, set the base_url argument:

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/peyton_manning.csv')

# Add date features for anomaly detection
# Here, we use date features at the month and year levels
anomalies_df_x = nixtla_client.detect_anomalies(
    df, time_col='timestamp', 
    target_col='value', 
    freq='D', 
    date_features=['month', 'year'],
    level=99.99,
)

# Plot weights of date features
nixtla_client.weights_x.plot.barh(x='features', y='weights')
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Calling Anomaly Detector Endpoint...
INFO:nixtla.nixtla_client:Using the following exogenous variables: month_1, month_2, month_3, month_4, month_5, month_6, month_7, month_8, month_9, month_10, month_11, month_12, year_2007, year_2008, year_2009, year_2010, year_2011, year_2012, year_2013, year_2014, year_2015, year_2016

📘

Available models in Azure AI

If you use an Azure AI endpoint, set model="azureai"

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

For the public API, two models are supported: timegpt-1 and timegpt-1-long-horizon.

By default, timegpt-1 is used. See this tutorial for details on using timegpt-1-long-horizon.

For more details, check out our in-depth tutorial on anomaly detection.