Skip to main content

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:

  1. Load anomaly scores and binary labels
  2. Evaluate a threshold with one of the built-in modes
  3. 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 F1
  • point-adjusted: if an anomaly event is detected once, the whole event is credited
  • composite: 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, recall
  • tp, tn, fp, fn
  • latency for point-adjusted evaluation when requested
  • detected_events, total_events for event-aware modes

search() returns a SearchResult with the best threshold and the corresponding MetricResult.

Validation Rules

  • score and label must be 1D and non-empty
  • score must be finite numeric values
  • label must be binary values 0 or 1
  • score and label must have the same length

Development

pip install -e .[dev]
pytest -q

Project details


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.2.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tadmetric-0.2.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file tadmetric-0.2.1.tar.gz.

File metadata

  • Download URL: tadmetric-0.2.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tadmetric-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ac75725f2a859b328861269bcfadb48187bdb1b0b3b0c084061d0406cf580640
MD5 9a1944a51ce6c8de419bf28bc8e880c9
BLAKE2b-256 db9ff3dcd295494c1dfe778214e1044094d6eb7691cd0c1716d92b22ee252c26

See more details on using hashes here.

File details

Details for the file tadmetric-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tadmetric-0.2.1-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

Hashes for tadmetric-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67a605d742c516cdabf4c624676785e5b41e88d313f4d4fc355286587b2ebce4
MD5 90bc69682cc339277605b60dc1f16763
BLAKE2b-256 703e9f76889ce7ef4e505739139f6c15f8540944e5414d5c8f83263aea8b6aef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page