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 the actual score values:

from tadmetric import Tadmetric

tm = Tadmetric(score, label)
best = tm.search(mode="point-adjusted")

print(best.threshold)
print(best.f1)
print(best.result.asdict())

search() checks the unique score levels directly. 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.0.tar.gz (8.3 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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tadmetric-0.2.0.tar.gz
  • Upload date:
  • Size: 8.3 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.0.tar.gz
Algorithm Hash digest
SHA256 5cfe722ef27660a17ff852ee105a15a4f99bed833f85a97a01f54e1555ec7b00
MD5 a48fdf7c14d72f6d75433642ac26a445
BLAKE2b-256 2e2b8c28d194dad35624749e093ce1be534d40872a0b4e645f3fc27e149f9c9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tadmetric-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deab3eaab6abc293425949741bf20ee9173ccd64c02237db9e105628ae932105
MD5 b978f4069cc36d1feed2ab7d7b58fa6b
BLAKE2b-256 26583f16678842120448b76a2badda3f59521e388ef73447667e68ce128c85ad

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