scientific-skills/aeon/references/anomaly_detection.md
Aeon provides anomaly detection methods for identifying unusual patterns in time series at both series and collection levels.
Detect anomalous time series within a collection:
ClassificationAdapter - Adapts classifiers for anomaly detection
OutlierDetectionAdapter - Wraps sklearn outlier detectors
Detect anomalous points or subsequences within a single time series.
Use similarity metrics to identify anomalies:
CBLOF - Cluster-Based Local Outlier Factor
KMeansAD - K-means based anomaly detection
LeftSTAMPi - Left STAMP incremental
STOMP - Scalable Time series Ordered-search Matrix Profile
MERLIN - Matrix profile-based method
LOF - Local Outlier Factor adapted for time series
ROCKAD - ROCKET-based semi-supervised detection
Analyze statistical distributions:
COPOD - Copula-Based Outlier Detection
DWT_MLEAD - Discrete Wavelet Transform Multi-Level Anomaly Detection
Use isolation principles:
IsolationForest - Random forest-based isolation
OneClassSVM - Support vector machine for novelty detection
STRAY - Streaming Robust Anomaly Detection
PyODAdapter - Bridges PyOD library to aeon
from aeon.anomaly_detection 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
Point anomalies: Single unusual values
Subsequence anomalies (discords): Unusual patterns
Collective anomalies: Groups of points forming unusual pattern
Specialized metrics for anomaly detection:
from aeon.benchmarking.metrics.anomaly_detection import (
range_precision,
range_recall,
range_f_score,
roc_auc_score
)
# Range-based metrics account for window detection
precision = range_precision(y_true, y_pred, alpha=0.5)
recall = range_recall(y_true, y_pred, alpha=0.5)
f1 = range_f_score(y_true, y_pred, alpha=0.5)