Local vs Global Anomaly Detection
Explore the differences between single and multiple variable anomaly detection approaches.
Overview
This guide demonstrates anomaly detection across multiple time series using local and global methods. You will learn: • How to detect anomalies in each time series independently (local). • How to detect anomalies across multiple correlated time series (global).
If you want to run this notebook interactively, click the badge below:
Both local and global methods rely on the Nixtla API for anomaly detection. The main difference is how anomalies are identified: individually per time series vs. collectively across multiple series at the same timestamp.
Setup
1. Install and Import Dependencies
If you haven’t already, install Nixtla and import your dependencies.
2. Connect to the Nixtla API
Create a NixtlaClient instance. Replace ‘my_api_key_provided_by_nixtla’ with your actual API key.
Use an Azure AI Endpoint
To use an Azure AI endpoint, set the base_url
argument explicitly:
1. Dataset
We use an example from the SMD dataset (SMD: Server Machine Dataset). This dataset is a benchmark for anomaly detection across correlated server-performance metrics (CPU, memory, disk I/O, network throughput, etc.).
File Used:
Data Size: 38 unique time series Frequency: Hourly (freq=‘h’)
2. local vs. Global Methods
Definition: local anomaly detection analyzes each time series in isolation. It flags anomalies based on each series’ individual deviation from its expected behavior.
Pros: Efficient for individual metrics or when correlations between metrics are not relevant.
Cons: May miss large-scale, system-wide anomalies that are only apparent when multiple series deviate simultaneously.
2.1.1 Example Usage
2.1.1 Example Usage
local detection code:
Sample output logs:
local Method Log Output
local Method Log Output
2.1.2 Visualization
2.1.2 Visualization
This figure highlights anomalies detected in four selected metrics. Each metric is analyzed independently, so anomalies reflect unusual behavior within that series alone.
local Anomaly Detection Results
Definition: local anomaly detection analyzes each time series in isolation. It flags anomalies based on each series’ individual deviation from its expected behavior.
Pros: Efficient for individual metrics or when correlations between metrics are not relevant.
Cons: May miss large-scale, system-wide anomalies that are only apparent when multiple series deviate simultaneously.
2.1.1 Example Usage
2.1.1 Example Usage
local detection code:
Sample output logs:
local Method Log Output
local Method Log Output
2.1.2 Visualization
2.1.2 Visualization
This figure highlights anomalies detected in four selected metrics. Each metric is analyzed independently, so anomalies reflect unusual behavior within that series alone.
local Anomaly Detection Results
Definition: Global anomaly detection considers all time series collectively. A time step is flagged as anomalous if the aggregate deviation across all series at that time exceeds a threshold.
Pros: Captures systemic or correlated anomalies that might be missed when analyzing each series in isolation.
Cons: Slightly higher complexity and computational overhead. May require careful threshold tuning.
2.2.1 Example Usage
2.2.1 Example Usage
global detection code:
Sample output logs:
global Method Log Output
global Method Log Output
2.2.2 Visualization
2.2.2 Visualization
In global mode, an anomaly is flagged when the combined deviation across these series reaches a threshold. This can reveal system-wide anomalies.
global Anomaly Detection Results
In global anomaly detection, anomaly scores from all series at each time step are aggregated. A step is anomalous if the combined score exceeds the threshold. This reveals systemic anomalies that may go unnoticed if each series is considered alone.
Summary
Local:
Best for detecting anomalies in a single metric or uncorrelated metrics. Low computational overhead, but may overlook cross-series patterns.
Global:
Considers correlations across metrics, capturing system-wide issues. More complex and computationally intensive than local methods.
Both detection approaches use Nixtla’s online anomaly detection method. Choose the strategy that best fits your use case and data characteristics.