A lightweight evaluation toolkit for time-series anomaly detection
Project description
tadmetric
Lightweight evaluation metrics for time-series anomaly detection.
tadmetric gives you a small, practical API for evaluating anomaly detection
results from either binary predictions or raw anomaly scores. The main workflow
is centered on evaluator(...), which lets you reuse one score array across
multiple metrics and threshold-search runs.
Why tadmetric
- Small API surface for common TSAD evaluation workflows
- Supports both
y_predandy_scorebased evaluation - Fast best-threshold search for repeated experiments
- Includes point-wise, event-wise, point-adjusted, composite, delay, and curve metrics
- Extensible metric registry for custom research metrics
Installation
pip install tadmetric
Python 3.9+ is supported.
Quick Start
1. Evaluate binary predictions
import tadmetric as tm
y_true = [0, 0, 1, 1, 1, 0, 0]
y_pred = [0, 0, 1, 1, 0, 0, 0]
result = tm.evaluate(y_true, y_pred, metrics=("point", "point_adjusted", "composite"))
print(result["point"].asdict())
print(result["point_adjusted"].f1)
print(result["composite"].f1)
2. Evaluate scores with a reusable evaluator
import tadmetric as tm
y_true = [0, 0, 1, 1, 1, 0, 0]
y_score = [0.1, 0.2, 0.4, 0.9, 0.7, 0.1, 0.0]
e = tm.evaluator(y_true, y_score)
point = e.point_wise(thr=0.5)
adjusted = e.point_adjusted(thr=0.3)
adjusted_k = e.point_adjusted_k(thr=0.3, k=30)
composite = e.composite(thr=0.5)
print(point.asdict())
print(adjusted.f1, adjusted_k.f1, composite.f1)
3. Search for the best threshold
import tadmetric as tm
y_true = [0, 0, 1, 1, 1, 0, 0]
y_score = [0.1, 0.2, 0.4, 0.9, 0.7, 0.1, 0.0]
e = tm.evaluator(y_true, y_score)
best = e.best(metric="composite", progress=True)
print(best.threshold)
print(best.f1)
print(best.evaluation["composite"].asdict())
progress=True writes to stderr. If you want to see it while running tests,
use pytest -s.
Main API
For most workflows, these are the core entry points:
evaluator(y_true, y_score)evaluate(y_true, y_pred, ...)evaluate_scores(y_true, y_score, threshold=...)e.point_wise(thr=...)e.point_adjusted(thr=...)e.point_adjusted_k(thr=..., k=...)e.composite(thr=...)e.best(metric=...)available_metrics()describe_metrics()api_overview()register_metric(...)
Included Metrics
Core precision / recall / F1
- Point-wise:
point_precision,point_recall,point_f1 - Point-adjusted:
point_adjusted_precision,point_adjusted_recall,point_adjusted_f1 - Point-adjusted
%K:point_adjusted_k_precision,point_adjusted_k_recall,point_adjusted_k_f1 - Composite:
composite_precision,composite_recall,composite_f1 - Event-wise:
event_precision,event_recall,event_f1
Delay-aware metrics
time_to_detectmean_time_to_detectmedian_time_to_detectmissed_detection_rate
Thresholding and utilities
threshold_by_quantilethreshold_by_topkthreshold_by_best_f1search_best_f1_thresholdapply_hysteresisscores_to_binarybinary_to_intervalsintervals_to_binarymerge_intervals
Curve-based metrics
precision_recall_curveroc_curveauc_prauc_roc
Metric Semantics
- Point-wise metrics treat each timestamp independently.
- Event-wise metrics treat each contiguous anomaly region as one event.
- Point-adjusted metrics credit a whole event once it is detected.
- Point-adjusted
%Kmetrics credit an event when at leastK%of the event is detected. - Composite metrics use point-wise precision and event-based recall.
- Interval semantics are half-open:
[start, end). - Event matching defaults to
overlap > 0. zero_divisiondefaults to0.0.
Discoverability
If you are opening the package for the first time, these helpers are useful:
import tadmetric as tm
print(tm.api_overview())
print(tm.available_metrics())
print([spec.asdict() for spec in tm.describe_metrics()])
Development
pip install -e .[dev]
pytest -q
Release Checklist
pytest -q
python -m build --no-isolation
python -m twine check dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tadmetric-0.1.7.tar.gz.
File metadata
- Download URL: tadmetric-0.1.7.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71b041c6c0e4f88d9e9d0510265680cd9a5e595f5f3f72cc679b4c8341426ef8
|
|
| MD5 |
c77c5d6e2156ed2b3aa8f58682518b64
|
|
| BLAKE2b-256 |
e48c25e5d983d2b28aba7498b709f8451cde6a13602a5f0fdd102d22d8833744
|
File details
Details for the file tadmetric-0.1.7-py3-none-any.whl.
File metadata
- Download URL: tadmetric-0.1.7-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4defa0e4647d81402664ffa10a97d5e2b834d996929d9ca9fe0924987a6a364
|
|
| MD5 |
1a2dc30d9e8f397056adbee37ad3ee1c
|
|
| BLAKE2b-256 |
2aa0a092385dd18104a2cd61c190a227b97c142109409533f04d655ca865429c
|