TODS Anomaly Detection
Use this skill when the task needs a full-stack time-series outlier detection pipeline rather than a single detector: preprocessing, time-series transforms, feature analysis, detector primitives, optional human-rule filtering, default pipeline evaluation, or AutoML search.
Important scope: TODS is a D3M-style pipeline system for multivariate time-series outlier detection. Its public docs are old (0.0.1 docs, PyPI 0.0.2 from 2020) and some APIs differ between docs and README; verify installed imports before production use.
Minimum Install
README install path:
sudo apt-get install libssl-dev libcurl4-openssl-dev libyaml-dev build-essential libopenblas-dev libcap-dev ffmpeg
git clone https://github.com/datamllab/tods.git
cd tods
pip install -e .
PyPI also lists pip install tods for 0.0.2, released September 21, 2020. README says Python 3.7+ and pip 19+; the hosted docs mention Python 3.6. Treat modern Python compatibility as unverified.
Data Contract
- Start from an ordered multivariate time-series table, usually a pandas
DataFrame converted with generate_dataset(df, target_index=...).
target_index points to the label/target column in the official examples.
- TODS primitives operate on D3M container datasets/DataFrames and pipeline semantic types such as
Attribute and TrueTarget.
- Detection outputs are binary labels where
1 marks outliers and 0 marks normal; many primitives also expose scores through produce_score.
- TODS targets three scenarios documented by README/docs: point-wise time-point outliers, pattern-wise subsequence outliers, and system-wise sets of time series as outliers.
Read references/tods-data-workflow.md before adapting CSVs, labels, entity panels, subsequence windows, or temporal validation.
Core Patterns
Default pipeline evaluation:
import pandas as pd
from tods import evaluate_pipeline, generate_dataset
from tods import schemas as schemas_utils
df = pd.read_csv("datasets/anomaly/raw_data/yahoo_sub_5.csv")
dataset = generate_dataset(df, target_index=6)
pipeline = schemas_utils.load_default_pipeline()
result = evaluate_pipeline(dataset, pipeline, "F1_MACRO")
print(result)
AutoML pipeline search:
import pandas as pd
from axolotl.backend.simple import SimpleRunner
from tods import generate_dataset, generate_problem
from tods.searcher import BruteForceSearch
df = pd.read_csv("datasets/yahoo_sub_5.csv")
dataset = generate_dataset(df, target_index=6)
problem = generate_problem(dataset, "F1_MACRO")
search = BruteForceSearch(problem_description=problem, backend=SimpleRunner(random_seed=0))
best_runtime, best_result = search.search_fit(input_data=[dataset], time_limit=30)
best_scores = search.evaluate(best_runtime.pipeline).scores
Manual D3M pipelines use Pipeline, PrimitiveStep, index.get_primitive(...), set_training_data, fit, produce, and produce_score. Read references/tods-api-map.md before constructing primitive paths.
Method Choice
- Use default pipeline when validating install/data conversion or establishing a baseline.
- Use AutoML
BruteForceSearch when the goal is pipeline search under a time budget.
- Use point-wise PyOD wrapper primitives for timestamp-level outlier labels on prepared features.
- Use
KDiscordODetect, MatrixProfile, DeepLog, Telemanom, LSTMODetect, or DAGMM for pattern-wise or sequence-model style detection only when their windowing assumptions match the task.
- Use
SystemWiseDetection and Ensemble only when the task is comparing sets of series or combining detector outputs.
- Use feature-analysis primitives when time/frequency/statistical features are needed inside the pipeline; fit them inside each temporal fold.
Evaluation and Plotting
- Official examples use
F1_MACRO; for anomaly labels also report precision, recall, F1 for the anomaly class, PR-AUC/average precision, ROC-AUC when valid, precision@N, false positives, and alert volume.
- For subsequence outputs, map each subsequence score to start/end timestamps before scoring.
- TODS docs do not document a dedicated plotting API. Plot original series, output labels, anomaly scores, and subsequence windows with matplotlib or Plotly outside TODS.
Anti-Leakage Rules
- Never random split time-indexed data for time-series anomaly detection. Use chronological or rolling-origin validation.
- Fit validation, imputation, scaling, smoothing, decomposition, feature extraction, detectors, AutoML search, thresholds, and reinforcement filters only on train/reference windows.
- Build lag/rolling/subsequence features from past/current values only for online detection; centered or full-series windows are retrospective.
- Tune
target_index, metric, primitive choices, contamination, window sizes, thresholds, and search budget on validation only.
- If labels are used by
generate_problem/evaluation, keep them out of Attribute features and final test selection.
- For panels or system-wise detection, split by time and preserve entity boundaries; do not let future behavior of one series set thresholds for another unless that is production-available.
Common Errors
- Treating TODS as a maintained modern PyOD replacement; it is an older pipeline system with pinned legacy dependencies.
- Passing raw timestamps or labels as detector features.
- Running AutoML search on the full dataset before temporal validation.
- Using
F1_MACRO alone on highly imbalanced anomalies without anomaly-class precision/recall.
- Calling pattern-wise subsequence labels point anomalies without documenting the window-to-point mapping.
- Assuming docs and README examples use the same import paths; verify installed version.
References
- Read
references/tods-api-map.md for official modules, primitives, detector inventory, APIs, and documented inconsistencies.
- Read
references/tods-data-workflow.md for data format, validation, pipeline search, metrics, and leakage controls.
- Read
references/official-sources.md for official sources consulted.
- Use
scripts/validate_tods_anomaly_input.py to sanity-check CSV inputs before generate_dataset or D3M pipeline construction.
Ready Checklist
- Task is time-series outlier detection and the desired output unit is point, subsequence, or series-set.
- Data is ordered, numeric where needed, and labels/target column are separated from attributes.
- Pipeline primitives and import paths are documented from official TODS sources.
- Temporal validation is defined before transforms, feature extraction, AutoML, and thresholding.
- Metrics include anomaly-class behavior, not only aggregate F1.
1---2name: anomaly-tods3description: Use TODS for automated time-series outlier detection after validating multivariate time-series data, including D3M pipeline primitives, default pipeline evaluation, AutoML pipeline search, point-wise, pattern-wise, and system-wise detection, PyOD wrappers, DeepLog, Telemanom, MatrixProfile, feature extraction, metrics, and anti-leakage safeguards.4---56# TODS Anomaly Detection78Use this skill when the task needs a full-stack time-series outlier detection pipeline rather than a single detector: preprocessing, time-series transforms, feature analysis, detector primitives, optional human-rule filtering, default pipeline evaluation, or AutoML search.910Important scope: TODS is a D3M-style pipeline system for multivariate time-series outlier detection. Its public docs are old (`0.0.1` docs, PyPI `0.0.2` from 2020) and some APIs differ between docs and README; verify installed imports before production use.1112## Minimum Install1314README install path:1516```bash17sudo apt-get install libssl-dev libcurl4-openssl-dev libyaml-dev build-essential libopenblas-dev libcap-dev ffmpeg18git clone https://github.com/datamllab/tods.git19cd tods20pip install -e .21```2223PyPI also lists `pip install tods` for `0.0.2`, released September 21, 2020. README says Python 3.7+ and pip 19+; the hosted docs mention Python 3.6. Treat modern Python compatibility as unverified.2425## Data Contract2627- Start from an ordered multivariate time-series table, usually a pandas `DataFrame` converted with `generate_dataset(df, target_index=...)`.28- `target_index` points to the label/target column in the official examples.29- TODS primitives operate on D3M container datasets/DataFrames and pipeline semantic types such as `Attribute` and `TrueTarget`.30- Detection outputs are binary labels where `1` marks outliers and `0` marks normal; many primitives also expose scores through `produce_score`.31- TODS targets three scenarios documented by README/docs: point-wise time-point outliers, pattern-wise subsequence outliers, and system-wise sets of time series as outliers.3233Read `references/tods-data-workflow.md` before adapting CSVs, labels, entity panels, subsequence windows, or temporal validation.3435## Core Patterns3637Default pipeline evaluation:3839```python40import pandas as pd41from tods import evaluate_pipeline, generate_dataset42from tods import schemas as schemas_utils4344df = pd.read_csv("datasets/anomaly/raw_data/yahoo_sub_5.csv")45dataset = generate_dataset(df, target_index=6)46pipeline = schemas_utils.load_default_pipeline()47result = evaluate_pipeline(dataset, pipeline, "F1_MACRO")48print(result)49```5051AutoML pipeline search:5253```python54import pandas as pd55from axolotl.backend.simple import SimpleRunner56from tods import generate_dataset, generate_problem57from tods.searcher import BruteForceSearch5859df = pd.read_csv("datasets/yahoo_sub_5.csv")60dataset = generate_dataset(df, target_index=6)61problem = generate_problem(dataset, "F1_MACRO")62search = BruteForceSearch(problem_description=problem, backend=SimpleRunner(random_seed=0))63best_runtime, best_result = search.search_fit(input_data=[dataset], time_limit=30)64best_scores = search.evaluate(best_runtime.pipeline).scores65```6667Manual D3M pipelines use `Pipeline`, `PrimitiveStep`, `index.get_primitive(...)`, `set_training_data`, `fit`, `produce`, and `produce_score`. Read `references/tods-api-map.md` before constructing primitive paths.6869## Method Choice7071- Use default pipeline when validating install/data conversion or establishing a baseline.72- Use AutoML `BruteForceSearch` when the goal is pipeline search under a time budget.73- Use point-wise PyOD wrapper primitives for timestamp-level outlier labels on prepared features.74- Use `KDiscordODetect`, `MatrixProfile`, `DeepLog`, `Telemanom`, `LSTMODetect`, or `DAGMM` for pattern-wise or sequence-model style detection only when their windowing assumptions match the task.75- Use `SystemWiseDetection` and `Ensemble` only when the task is comparing sets of series or combining detector outputs.76- Use feature-analysis primitives when time/frequency/statistical features are needed inside the pipeline; fit them inside each temporal fold.7778## Evaluation and Plotting7980- Official examples use `F1_MACRO`; for anomaly labels also report precision, recall, F1 for the anomaly class, PR-AUC/average precision, ROC-AUC when valid, precision@N, false positives, and alert volume.81- For subsequence outputs, map each subsequence score to start/end timestamps before scoring.82- TODS docs do not document a dedicated plotting API. Plot original series, output labels, anomaly scores, and subsequence windows with matplotlib or Plotly outside TODS.8384## Anti-Leakage Rules8586- Never random split time-indexed data for time-series anomaly detection. Use chronological or rolling-origin validation.87- Fit validation, imputation, scaling, smoothing, decomposition, feature extraction, detectors, AutoML search, thresholds, and reinforcement filters only on train/reference windows.88- Build lag/rolling/subsequence features from past/current values only for online detection; centered or full-series windows are retrospective.89- Tune `target_index`, metric, primitive choices, contamination, window sizes, thresholds, and search budget on validation only.90- If labels are used by `generate_problem`/evaluation, keep them out of `Attribute` features and final test selection.91- For panels or system-wise detection, split by time and preserve entity boundaries; do not let future behavior of one series set thresholds for another unless that is production-available.9293## Common Errors9495- Treating TODS as a maintained modern PyOD replacement; it is an older pipeline system with pinned legacy dependencies.96- Passing raw timestamps or labels as detector features.97- Running AutoML search on the full dataset before temporal validation.98- Using `F1_MACRO` alone on highly imbalanced anomalies without anomaly-class precision/recall.99- Calling pattern-wise subsequence labels point anomalies without documenting the window-to-point mapping.100- Assuming docs and README examples use the same import paths; verify installed version.101102## References103104- Read `references/tods-api-map.md` for official modules, primitives, detector inventory, APIs, and documented inconsistencies.105- Read `references/tods-data-workflow.md` for data format, validation, pipeline search, metrics, and leakage controls.106- Read `references/official-sources.md` for official sources consulted.107- Use `scripts/validate_tods_anomaly_input.py` to sanity-check CSV inputs before `generate_dataset` or D3M pipeline construction.108109## Ready Checklist110111- Task is time-series outlier detection and the desired output unit is point, subsequence, or series-set.112- Data is ordered, numeric where needed, and labels/target column are separated from attributes.113- Pipeline primitives and import paths are documented from official TODS sources.114- Temporal validation is defined before transforms, feature extraction, AutoML, and thresholding.115- Metrics include anomaly-class behavior, not only aggregate F1.