Skip to main content

No project description provided

Project description

Latest Version Supported Python Versions Documentation Status Pre-Commit enabled MyPy checked Code Coverage

Faster implementation (~200x) of the enhanced time-aware precision and recall (eTaPR) from Hwang et al. The original implementation is saurf4ng/eTaPR and this implementation is fully tested against it.

Motivation

The motivation behind the eTaPR is that it is enough for a detection method to partially detect an anomaly segment, as along as an human expert can find the anomaly around this prediction. The following illustration (a recreation from the paper) highlights the four cases which are considered by eTaPR:

Motivation behind eTaPR
  1. A successful detection: A human expert can likely find the anomaly \(A_1\) based on the prediction \(P_1\).

  2. A failed detection: Only a small portion of the prediction \(P_2\) overlaps with the anomaly \(A_2\).

  3. A failed detection: Most of the prediction \(P_3\) lies in the range of non-anomalous behavior (prediction starts too early). A human expert will likely regard the prediction \(P_3\) as incorrect or a false alarm. The prediction \(P_3\) is too imprecise and the anomaly \(A_3\) is likely to be missed.

  4. A failed prediction: The prediction \(P_4\) mostly overlaps with the anomaly \(A_4\), but covers only a small portion of the actual anomaly segment. Thus, a human expert is likely to dismiss the prediction \(P_4\) as incorrect because the full extend of the anomaly remains hidden. The prediction P_4 contains insufficient information about the anomaly.

Note that for case 4, we could still mark the anomaly as detected, if there were more predictions which overlap with the anomaly \(A_4\). Specifically, the handling of the cases 3 and 4 is what sets eTaPR apart from other scoring methods.

If you want an in-depth explanation of the calculation, check out the documentation.

Getting Started

Install this package from PyPI using pip or uv:

pip install faster-etapr
uv pip install faster-etapr

Now, you run your evaluation in python:

import faster_etapr
faster_etapr.evaluate_from_ranges(
    y_hat=[0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0],
    y=    [0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1],
    theta_p=0.5,
    theta_r=0.1,
)
{
    'eta/recall': 0.3875,
    'eta/recall_detection': 0.5,
    'eta/recall_portion': 0.275,
    'eta/detected_anomalies': 2.0,
    'eta/precision': 0.46476766302377037,
    'eta/precision_detection': 0.46476766302377037,
    'eta/precision_portion': 0.46476766302377037,
    'eta/correct_predictions': 2.0,
    'eta/f1': 0.4226312395393011,
    'eta/TP': 4,
    'eta/FP': 5,
    'eta/FN': 7,
    'eta/wrong_predictions': 2,
    'eta/missed_anomalies': 2,
    'eta/anomalies': 4,
    'eta/segments': 0.499999999999875,
    'point/recall': 0.45454545454541323,
    'point/precision': 0.5555555555554939,
    'point/f1': 0.49999999999945494,
    'point/TP': 5,
    'point/FP': 4,
    'point/FN': 6,
    'point/anomalies': 4,
    'point/detected_anomalies': 3.0,
    'point/segments': 0.75,
    'point_adjust/recall': 0.9090909090909091,
    'point_adjust/precision': 0.7142857142857143,
    'point_adjust/f1': 0.7999999999995071
}

We calculate three types of metrics:

Benchmark

A little benchmark with randomly generated inputs (np.random.randint(0, 2, size=size)):

size

eTaPR_pkg

faster_etapr

factor

1 000

0.4090

0.0032

~125x

10 000

35.8264

0.1810

~198x

20 000

148.2670

0.6547

~226x

100 000

too long

55.04712

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

faster_etapr-0.1.1.tar.gz (239.8 kB view details)

Uploaded Source

Built Distribution

faster_etapr-0.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file faster_etapr-0.1.1.tar.gz.

File metadata

  • Download URL: faster_etapr-0.1.1.tar.gz
  • Upload date:
  • Size: 239.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for faster_etapr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e31e93d668e06a09ee4073811de2bc094cfd6f3941397801f6d13f3b7b9b2ac3
MD5 29643c468710f701c924110e72eccb35
BLAKE2b-256 9974a526ca488ac4d81cec910e34d211127a76ff21f029a0421d7b36c9aef2f3

See more details on using hashes here.

File details

Details for the file faster_etapr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: faster_etapr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for faster_etapr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 07e3637d84bc8ff9e74d0d65b3c61bfafffff39794f03d2c28c94bb15f1d75a8
MD5 a68dee347e0ef699f83b1fe05ce856c9
BLAKE2b-256 1e012899dd7781e36eada386a7daf251e18a53edd664fb6009fb926cb0d15feb

See more details on using hashes here.

Supported by

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