A lightweight evaluation toolkit for time-series anomaly detection
Project description
tadmetric
A lightweight evaluation toolkit for time-series anomaly detection.
tadmetric provides point-wise, event-wise, point-adjusted, composite, and delay-aware
metrics, along with utilities for thresholding and interval conversion.
Installation
pip install tadmetric
Quick example
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())
from tadmetric import threshold_by_best_f1
best_threshold = threshold_by_best_f1(y_true, y_score, metric="composite")
Concepts
- Point-wise metrics treat each timestamp independently.
- Event-wise metrics treat each contiguous anomaly region as one event.
- Point-adjusted metrics credit an anomaly event if it is detected at least once.
- Point-adjusted %K metrics credit an anomaly event when at least
K%of the event is detected. - Composite metrics combine time-wise precision with event-based recall.
- Delay-aware metrics measure how long it takes to first detect each event.
Design choices
- Interval semantics are half-open:
[start, end). - Event matching defaults to
overlap > 0. - Zero division returns
0.0by default. - Internally, event logic uses interval lists like
[(start, end), ...].
API overview
Point-wise
point_precisionpoint_recallpoint_f1
Event-wise
event_precisionevent_recallevent_f1
Point-adjusted
point_adjusted_precisionpoint_adjusted_recallpoint_adjusted_f1point_adjusted_k_precisionpoint_adjusted_k_recallpoint_adjusted_k_f1
Composite
composite_precisioncomposite_recallcomposite_f1
Delay-aware
time_to_detectmean_time_to_detectmedian_time_to_detectmissed_detection_rate
Thresholding and conversion
threshold_by_quantilethreshold_by_topkthreshold_by_best_f1search_best_f1_thresholdapply_hysteresisbinary_to_intervalsintervals_to_binarymerge_intervals
Curve-based
precision_recall_curveroc_curveauc_prauc_roc
High-level API
evaluateevaluate_scoresregister_metricavailable_metrics
Development
pip install -e .[dev]
pytest
Packaging
python -m build
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
tadmetric-0.1.0.tar.gz
(10.6 kB
view details)
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
tadmetric-0.1.0-py3-none-any.whl
(12.6 kB
view details)
File details
Details for the file tadmetric-0.1.0.tar.gz.
File metadata
- Download URL: tadmetric-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c94f362c7e41e6a3966b0fd62409f34eed83b7c2786919879b00249036f63228
|
|
| MD5 |
fcf1d6f5adbf6a07fb532bd8ba26c8eb
|
|
| BLAKE2b-256 |
5206da8fee418e9c63252c5ad79728ebe7a758bb3d55b806cdfdff37bcc1efb3
|
File details
Details for the file tadmetric-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tadmetric-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 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 |
ac680ecd7c44466f7f07d0f067670c91ee566760b03063fc89b2b73ebebaefaf
|
|
| MD5 |
e40e9ccb2459085c1d490c41acd416c2
|
|
| BLAKE2b-256 |
622884ca351e2dcc4b2f6e9f130a0f0ea19cadb0a0a4f19cd4877c956146b5dc
|