A lightweight evaluation toolkit for time-series anomaly detection
Project description
tadmetric
Lightweight evaluation utilities for time-series anomaly detection.
tadmetric is now centered on one small class, Tadmetric, for the workflow:
- Load anomaly scores and binary labels
- Evaluate a threshold with one of the built-in modes
- Search for the best threshold when needed
Installation
pip install tadmetric
Python 3.9+ is supported.
Quick Start
from tadmetric import Tadmetric
score = [0.1, 0.2, 0.4, 0.9, 0.7, 0.1, 0.0]
label = [0, 0, 1, 1, 1, 0, 0]
tm = Tadmetric(score, label)
point = tm.evaluate(0.5, mode="point-wise")
adjusted = tm.evaluate(0.5, mode="point-adjusted", calc_latency=True)
composite = tm.evaluate(0.5, mode="composite")
print(point.asdict())
print(adjusted.latency)
print(composite.f1)
Modes
point-wise: regular point-level precision, recall, and F1point-adjusted: if an anomaly event is detected once, the whole event is creditedcomposite: point-wise precision with event-wise recall
The mode argument accepts a few aliases such as point, point_wise, point_adjusted, and comp.
Threshold Search
Use search() when you want the best threshold over a threshold grid:
from tadmetric import Tadmetric
tm = Tadmetric(score, label)
best = tm.search(mode="point-adjusted")
print(best.threshold)
print(best.f1)
print(best.result.asdict())
By default, search() scans steps=100 thresholds from score.min() to score.max(). If multiple thresholds tie, it prefers the higher threshold.
best = tm.search(start=0.0, end=1.0, steps=101, mode="point-wise", verbose=False)
Returned Objects
evaluate() returns a MetricResult with:
f1,precision,recalltp,tn,fp,fnlatencyfor point-adjusted evaluation when requesteddetected_events,total_eventsfor event-aware modes
search() returns a SearchResult with the best threshold and the corresponding MetricResult.
Validation Rules
scoreandlabelmust be 1D and non-emptyscoremust be finite numeric valueslabelmust be binary values0or1scoreandlabelmust have the same length
Development
pip install -e .[dev]
pytest -q
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.2.2.tar.gz.
File metadata
- Download URL: tadmetric-0.2.2.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f9accdb33d554e335664b56033e97261091d499823d1cfeb5d1df075465095f
|
|
| MD5 |
ee0a461d8202d479459c6ef65381f309
|
|
| BLAKE2b-256 |
94c92ccfe851cdeeb6d8c4ad70313472715dcedbdb78f28e45ab2a3e6fc8366a
|
File details
Details for the file tadmetric-0.2.2-py3-none-any.whl.
File metadata
- Download URL: tadmetric-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.4 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 |
c565ab888a55ab8b74cafeb75b62e723b75525fe6f356f1f94953ac53512d81b
|
|
| MD5 |
fb36e62811c5cd1ce60818782928d0a5
|
|
| BLAKE2b-256 |
e615cd9026c0be6ba343ec97a4bb6c3710e3489a0a69a08eba6abd4b2faf929b
|