Examples¶
PyOD offers three ways to do anomaly detection, from simple to fully agentic. This section is organized around those three layers, plus by data type and advanced topics.
Three Approaches to PyOD¶
Layer 1: Classic API. Pick a detector, fit, predict. Best when you know which detector you want.
from pyod.models.iforest import IForest
clf = IForest()
clf.fit(X_train)
scores = clf.decision_scores_
See Layer 1: Tabular Anomaly Detection, Layer 1: Time Series Anomaly Detection, Layer 1: Graph Anomaly Detection, Layer 1: Text and Image Anomaly Detection.
Layer 2: ADEngine. Let PyOD choose, compare, and assess. Best when you do not know which detector to use.
from pyod.utils.ad_engine import ADEngine
state = ADEngine().investigate(X)
print(state.analysis['summary'])
See Layer 2: ADEngine Lifecycle Orchestration.
Layer 3: Agentic Investigation. Any AI agent drives the workflow through natural conversation. Best for interactive use with user feedback.
User: I have some cardiotocography data. Can you find abnormal cases?
Agent: Found 172 anomalies in 1831 recordings (9.4%) by consensus of 3
detectors (IForest, ECOD, KNN). Agreement is 0.68 (Spearman).
Top case is recording #1656 (IForest raw score 0.17, 100th pctile).
Should I dig deeper or iterate?
User: Focus on the top 50 and cross-check against the clinical labels.
Agent: [runs analyze() with tighter top-k, validates against ground truth]
Behind the scenes the agent calls engine.investigate(), iterate(), and report(),
following state.next_action at each step. See Layer 3: Agentic Investigation for the full walkthrough.
Examples by Data Type¶
Layer 1: Tabular Anomaly Detection: 43 detectors for tabular data (ECOD, IForest, KNN, LOF, …)
Layer 1: Time Series Anomaly Detection: 5 shipped + 2 experimental time series detectors (KShape, MatrixProfile, SpectralResidual, …)
Layer 1: Graph Anomaly Detection: 8 graph detectors (DOMINANT, CoLA, CONAD, …)
Layer 1: Text and Image Anomaly Detection: Text and image detection via foundation model embeddings
Advanced Topics¶
Model Combination: Model combination (average, max, AOM, MOA)
Thresholding: Data-driven threshold selection
Featured Tutorials¶
External tutorials and articles about PyOD:
Analytics Vidhya: An Awesome Tutorial to Learn Outlier Detection in Python using PyOD Library
KDnuggets: Intuitive Visualization of Outlier Detection Methods
Towards Data Science: Anomaly Detection for Dummies
awesome-machine-learning: General-Purpose Machine Learning