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.

PyOD 3 agentic investigation demo

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


Advanced Topics