A lightweight evaluation toolkit for time-series anomaly detection
Project description
tadmetric
Lightweight evaluation metrics for time-series anomaly detection.
tadmetric helps you evaluate anomaly scores or binary predictions with a small,
simple API. It includes point-wise metrics, point-adjusted metrics, point-adjusted
%K, composite metrics, event-wise metrics, delay-aware metrics, and threshold search.
Installation
pip install tadmetric
Why tadmetric?
- Minimal input: use
y_truewith eithery_predory_score - Practical TSAD metrics in one place
- Fast threshold search for best F1
- Easy high-level API for benchmarking multiple metrics at once
- Extensible metric registry for adding new custom metrics
Quick start
Evaluate from anomaly scores
from tadmetric import evaluate_scores
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]
result = evaluate_scores(
y_true,
y_score,
threshold=0.5,
metric_kwargs={"point_adjusted_k": {"k": 50}},
)
print(result["point"].asdict())
print(result["point_adjusted"].asdict())
print(result["point_adjusted_k"].asdict())
print(result["composite"].asdict())
Find the best threshold
from tadmetric import search_best_f1_threshold
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]
best = search_best_f1_threshold(y_true, y_score, metric="composite")
print(best.threshold)
print(best.f1)
print(best.evaluation["composite"].asdict())
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_hysteresisbinary_to_intervalsintervals_to_binarymerge_intervalsscores_to_binary
Curve-based metrics
precision_recall_curveroc_curveauc_prauc_roc
High-level API
For most workflows, these are the main entry points:
evaluateevaluate_scoresavailable_metricsregister_metric
Metric semantics
- Point-wise metrics treat each timestamp independently.
- Event-wise metrics treat each contiguous anomaly region as one event.
- Point-adjusted metrics credit an event if it is detected at least once.
- Point-adjusted
%Kmetrics credit an event when at leastK%of the event is detected. - Composite metrics use time-wise precision and event-based recall.
- Interval semantics are half-open:
[start, end). - Event matching defaults to
overlap > 0. - Zero division returns
0.0by default.
Development
pip install -e .[dev]
pytest
Build
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.1.tar.gz.
File metadata
- Download URL: tadmetric-0.1.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca7327dbaebbe25a288b453ebd0acf34fc2e8cb6bdff1ecf8e4e2d24d0f87da4
|
|
| MD5 |
e8b2fee46e4f8bd62a46e24f85e4e0be
|
|
| BLAKE2b-256 |
ff683c3d21f6885fe3c9fdaef45affc1a5909f7c08ad1328990e719ff0110122
|
File details
Details for the file tadmetric-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tadmetric-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.8 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 |
9f622ac9566d4246a17a03cd7404e74b5ff19e68f659beea33ef62927d11a4b4
|
|
| MD5 |
ddc4163f7930e1fa6a6c060490183117
|
|
| BLAKE2b-256 |
ccfc0a5c5969972f4e8a1e1ca5f1553697a205899f87f759e4495a58ca34ed23
|