Skill Tracer
Skills › Scientific Agent Skills › aeon › anomaly_detection.md

anomaly_detection.md

151 lines · skills/aeon/references/anomaly_detection.md at 5f2bc03

Open on GitHub
1# Anomaly Detection
2
3Aeon 1.6 provides series and collection detectors. Import collection adapters from `aeon.anomaly_detection.collection`; series methods live under `.series.distance_based`, `.series.distribution_based`, `.series.outlier_detection`, or `.series.adapters`.
4

Anomaly Detection

Aeon 1.6 provides series and collection detectors. Import collection adapters from aeon.anomaly_detection.collection; series methods live under .series.distance_based, .series.distribution_based, .series.outlier_detection, or .series.adapters.

Raw lines 1 to 4
5## Collection Anomaly Detectors
6
7Detect anomalous time series within a collection:
8
9- `ClassificationAdapter` - Adapts classifiers for anomaly detection
10 - Supervised classification of labeled normal and anomalous series
11 - **Use when**: Have labels for both normal and anomalous cases
13- `OutlierDetectionAdapter` - Wraps sklearn outlier detectors
14 - Works with IsolationForest, LOF, OneClassSVM
15 - **Use when**: Want to use sklearn anomaly detectors on collections

Collection Anomaly Detectors

Detect anomalous time series within a collection:

  • ClassificationAdapter - Adapts classifiers for anomaly detection
  • Supervised classification of labeled normal and anomalous series
  • Use when: Have labels for both normal and anomalous cases
  • OutlierDetectionAdapter - Wraps sklearn outlier detectors
  • Works with IsolationForest, LOF, OneClassSVM
  • Use when: Want to use sklearn anomaly detectors on collections
Raw lines 5 to 16
17## Series Anomaly Detectors
19Detect anomalous points or subsequences within a single time series.

Series Anomaly Detectors

Detect anomalous points or subsequences within a single time series.

Raw lines 17 to 20
21### Distance-Based Methods
23Use similarity metrics to identify anomalies:
25- `CBLOF` - Cluster-Based Local Outlier Factor
26 - Clusters data, identifies outliers based on cluster properties
27 - **Use when**: Anomalies form sparse clusters
29- `KMeansAD` - K-means based anomaly detection
30 - Distance to nearest cluster center indicates anomaly
31 - **Use when**: Normal patterns cluster well
33- `LeftSTAMPi` - Left STAMP incremental
34 - Matrix profile for online anomaly detection
35 - **Use when**: Streaming data, need online detection
37- `STOMP` - Scalable Time series Ordered-search Matrix Profile
38 - Computes matrix profile for subsequence anomalies
39 - **Use when**: Discord discovery, motif detection
41- `MERLIN` - Matrix profile-based method
42 - Efficient matrix profile computation
43 - **Use when**: Large time series, need scalability
45- `LOF` - Local Outlier Factor adapted for time series
46 - Density-based outlier detection
47 - **Use when**: Anomalies in low-density regions
49- `ROCKAD` - ROCKET-based semi-supervised detection
50 - Uses ROCKET features for anomaly identification
51 - **Use when**: Have clean normal training data for novelty detection

Distance-Based Methods

Use similarity metrics to identify anomalies:

  • CBLOF - Cluster-Based Local Outlier Factor
  • Clusters data, identifies outliers based on cluster properties
  • Use when: Anomalies form sparse clusters
  • KMeansAD - K-means based anomaly detection
  • Distance to nearest cluster center indicates anomaly
  • Use when: Normal patterns cluster well
  • LeftSTAMPi - Left STAMP incremental
  • Matrix profile for online anomaly detection
  • Use when: Streaming data, need online detection
  • STOMP - Scalable Time series Ordered-search Matrix Profile
  • Computes matrix profile for subsequence anomalies
  • Use when: Discord discovery, motif detection
  • MERLIN - Matrix profile-based method
  • Efficient matrix profile computation
  • Use when: Large time series, need scalability
  • LOF - Local Outlier Factor adapted for time series
  • Density-based outlier detection
  • Use when: Anomalies in low-density regions
  • ROCKAD - ROCKET-based semi-supervised detection
  • Uses ROCKET features for anomaly identification
  • Use when: Have clean normal training data for novelty detection
Raw lines 21 to 52
53### Distribution-Based Methods
55Analyze statistical distributions:
57- `COPOD` - Copula-Based Outlier Detection
58 - Models marginal and joint distributions
59 - **Use when**: Multi-dimensional time series, complex dependencies
61- `DWT_MLEAD` - Discrete Wavelet Transform Multi-Level Anomaly Detection
62 - Decomposes series into frequency bands
63 - **Use when**: Anomalies at specific frequencies

Distribution-Based Methods

Analyze statistical distributions:

  • COPOD - Copula-Based Outlier Detection
  • Models marginal and joint distributions
  • Use when: Multi-dimensional time series, complex dependencies
  • DWT_MLEAD - Discrete Wavelet Transform Multi-Level Anomaly Detection
  • Decomposes series into frequency bands
  • Use when: Anomalies at specific frequencies
Raw lines 53 to 64
65### Isolation-Based Methods
67Use isolation principles:
69- `IsolationForest` - Random forest-based isolation
70 - Anomalies easier to isolate than normal points
71 - **Use when**: High-dimensional data, no assumptions about distribution
73- `OneClassSVM` - Support vector machine for novelty detection
74 - Learns boundary around normal data
75 - **Use when**: Well-defined normal region, need robust boundary
77- `STRAY` - Streaming Robust Anomaly Detection
78 - Robust to data distribution changes
79 - **Use when**: Streaming data, distribution shifts

Isolation-Based Methods

Use isolation principles:

  • IsolationForest - Random forest-based isolation
  • Anomalies easier to isolate than normal points
  • Use when: High-dimensional data, no assumptions about distribution
  • OneClassSVM - Support vector machine for novelty detection
  • Learns boundary around normal data
  • Use when: Well-defined normal region, need robust boundary
  • STRAY - Streaming Robust Anomaly Detection
  • Robust to data distribution changes
  • Use when: Streaming data, distribution shifts
Raw lines 65 to 80
81### External Library Integration
83- `PyODAdapter` - Bridges PyOD library to aeon
84 - Access 40+ PyOD anomaly detectors
85 - **Use when**: Need specific PyOD algorithm

External Library Integration

  • PyODAdapter - Bridges PyOD library to aeon
  • Access 40+ PyOD anomaly detectors
  • Use when: Need specific PyOD algorithm
Raw lines 81 to 86
87## Quick Start
89```python
90from aeon.anomaly_detection.series.distance_based import STOMP
91import numpy as np
93# Create time series with anomaly
94y = np.concatenate([
95 np.sin(np.linspace(0, 10, 100)),
96 [5.0], # Anomaly spike
97 np.sin(np.linspace(10, 20, 100))
98])
100# Detect anomalies
101detector = STOMP(window_size=10)
102anomaly_scores = detector.fit_predict(y)
104# Higher scores indicate more anomalous points
105threshold = np.percentile(anomaly_scores, 95)
106anomalies = anomaly_scores > threshold
107```
109STOMP requires `stumpy` and supports univariate input. Its output contains one score per timepoint after aggregating overlapping windows, unlike the shorter raw matrix profile. A percentile threshold on the evaluated series is exploratory and forces a chosen alert fraction; calibrate on independent normal/validation data for deployment. These scores are not anomaly probabilities.

Quick Start

from aeon.anomaly_detection.series.distance_based import STOMP
import numpy as np

# Create time series with anomaly
y = np.concatenate([
    np.sin(np.linspace(0, 10, 100)),
    [5.0],  # Anomaly spike
    np.sin(np.linspace(10, 20, 100))
])

# Detect anomalies
detector = STOMP(window_size=10)
anomaly_scores = detector.fit_predict(y)

# Higher scores indicate more anomalous points
threshold = np.percentile(anomaly_scores, 95)
anomalies = anomaly_scores > threshold

STOMP requires stumpy and supports univariate input. Its output contains one score per timepoint after aggregating overlapping windows, unlike the shorter raw matrix profile. A percentile threshold on the evaluated series is exploratory and forces a chosen alert fraction; calibrate on independent normal/validation data for deployment. These scores are not anomaly probabilities.

Raw lines 87 to 110
111## Point vs Subsequence Anomalies
113- **Point anomalies**: Single unusual values
114 - Use: COPOD, DWT_MLEAD, IsolationForest
116- **Subsequence anomalies** (discords): Unusual patterns
117 - Use: STOMP, LeftSTAMPi, MERLIN
119- **Collective anomalies**: Groups of points forming unusual pattern
120 - Use: Matrix profile methods, clustering-based

Point vs Subsequence Anomalies

  • Point anomalies: Single unusual values
  • Use: COPOD, DWT_MLEAD, IsolationForest
  • Subsequence anomalies (discords): Unusual patterns
  • Use: STOMP, LeftSTAMPi, MERLIN
  • Collective anomalies: Groups of points forming unusual pattern
  • Use: Matrix profile methods, clustering-based
Raw lines 111 to 121
122## Evaluation Metrics
124Specialized metrics for anomaly detection:
126```python
127from aeon.benchmarking.metrics.anomaly_detection import range_roc_auc_score
129# Binary true labels and continuous anomaly scores.
130auc = range_roc_auc_score(y_true, anomaly_scores)
131```
133`range_precision`, `range_recall`, and `range_f_score` need `prts`; its published NumPy<2 requirement conflicts with aeon 1.6's NumPy>=2 requirement. Treat these as dependency-blocked API references, not runnable examples in the core environment. If a separately validated compatible environment is available, precision/recall take `alpha`; F-score takes separate `p_alpha` and `r_alpha` (not `alpha`). Their inputs are binary labels. Do not bypass dependency constraints without validating the upstream combination.

Evaluation Metrics

Specialized metrics for anomaly detection:

from aeon.benchmarking.metrics.anomaly_detection import range_roc_auc_score

# Binary true labels and continuous anomaly scores.
auc = range_roc_auc_score(y_true, anomaly_scores)

range_precision, range_recall, and range_f_score need prts; its published NumPy<2 requirement conflicts with aeon 1.6's NumPy>=2 requirement. Treat these as dependency-blocked API references, not runnable examples in the core environment. If a separately validated compatible environment is available, precision/recall take alpha; F-score takes separate p_alpha and r_alpha (not alpha). Their inputs are binary labels. Do not bypass dependency constraints without validating the upstream combination.

Raw lines 122 to 134
135## Algorithm Selection
137- **Speed priority**: KMeansAD, IsolationForest
138- **Accuracy priority**: STOMP, COPOD
139- **Streaming data**: LeftSTAMPi, STRAY
140- **Discord discovery**: STOMP, MERLIN
141- **Multi-dimensional**: COPOD, PyODAdapter
142- **Semi-supervised**: ROCKAD, OneClassSVM
143- **No training data**: IsolationForest, STOMP

Algorithm Selection

  • Speed priority: KMeansAD, IsolationForest
  • Accuracy priority: STOMP, COPOD
  • Streaming data: LeftSTAMPi, STRAY
  • Discord discovery: STOMP, MERLIN
  • Multi-dimensional: COPOD, PyODAdapter
  • Semi-supervised: ROCKAD, OneClassSVM
  • No training data: IsolationForest, STOMP
Raw lines 135 to 144
145## Best Practices
1471. **Normalize data**: Many methods sensitive to scale
1482. **Choose window size**: For matrix profile methods, window size critical
1493. **Set threshold**: Use percentile-based or domain-specific thresholds
1504. **Validate results**: Visualize detections to verify meaningfulness
1515. **Handle seasonality**: Detrend/deseasonalize before detection

Best Practices

  1. Normalize data: Many methods sensitive to scale
  2. Choose window size: For matrix profile methods, window size critical
  3. Set threshold: Use percentile-based or domain-specific thresholds
  4. Validate results: Visualize detections to verify meaningfulness
  5. Handle seasonality: Detrend/deseasonalize before detection
Raw lines 145 to 151