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.2.tar.gz (9.2 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.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for tadmetric-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4f9accdb33d554e335664b56033e97261091d499823d1cfeb5d1df075465095f
MD5 ee0a461d8202d479459c6ef65381f309
BLAKE2b-256 94c92ccfe851cdeeb6d8c4ad70313472715dcedbdb78f28e45ab2a3e6fc8366a

See more details on using hashes here.

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

Hashes for tadmetric-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c565ab888a55ab8b74cafeb75b62e723b75525fe6f356f1f94953ac53512d81b
MD5 fb36e62811c5cd1ce60818782928d0a5
BLAKE2b-256 e615cd9026c0be6ba343ec97a4bb6c3710e3489a0a69a08eba6abd4b2faf929b

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