Overview

Configure the confidence levels for historical anomaly detection. By default, any values that lie outside the 99% confidence interval are labeled as anomalies.

Adjusting the confidence level using the level parameter allows you to modify how many anomalies the system detects.

• Increasing the level(closer to 100) decreases the number of anomalies.
• Decreasing the level(closer to 0) increases the number of anomalies.

You can set any numeric value between 0 and 100 (including decimals) for the level parameter.

Key Concepts

Confidence Interval
The range of values within which a certain percentage of anomalies are expected to fall. A 99% interval (the default) means there is only a 1% chance of data lying outside this range.

API Key
An authentication token (often stored in your environment) that grants secure access to Nixtla’s services.

Azure AI Models
If using Azure AI endpoints, you can specify different models (e.g., azureai) for anomaly detection.

Step-by-Step Instructions

1

Install and Import

Import Nixtla and Pandas
import pandas as pd
from nixtla import NixtlaClient

Make sure Nixtla is installed along with any required libraries such as pandas.

2

Initialize the Client

Initialize NixtlaClient with API key
nixtla_client = NixtlaClient(
    # defaults to os.environ.get("NIXTLA_API_KEY")
    api_key='my_api_key_provided_by_nixtla'
)

Provide your Nixtla API key here if not already set in your environment variables.

3

(Optional) Use an Azure AI Endpoint

4

Read Your Data

Load Time Series Data
# Read the data
df = pd.read_csv("https://datasets-nixtla.s3.amazonaws.com/peyton-manning.csv")

Load the time series data you want to analyze for anomalies.

5

Detect Anomalies

Detect Anomalies with 70% Confidence Level
# Anomaly detection using a 70% confidence interval
anomalies_df = nixtla_client.detect_anomalies(
    df,
    freq='D',
    level=70
)

Adjust the level to your desired confidence interval (0–100).

6

Visualize Results

Plot Anomalies
# Plot anomalies
nixtla_client.plot(df, anomalies_df)

Generate a plot showing which time points were flagged as anomalies.

Below is an example of the console logs you might see during anomaly detection:

Example Output

Anomalies detected with a 70% confidence interval

Available Models

Learn More

To explore more in-depth tutorials and examples, see the Anomaly Detection Tutorial in the Nixtla documentation.