Skip to main content

No project description provided

Project description

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

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

Uploaded Source

Built Distribution

faster_etapr-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: faster_etapr-0.1.0.tar.gz
  • Upload date:
  • Size: 239.1 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.0.tar.gz
Algorithm Hash digest
SHA256 9f344dc2eb4bb2bcdc1c08b4462c46e41d0188091e01d98b1a62063eb3cbccc9
MD5 448c507a38bb08ada7f37df738ad1ede
BLAKE2b-256 1537f3be67ae586a5cb416fef264adcff12b5fa3e58c7e319c89308e25fcd69d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: faster_etapr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c08aef8d9eaad42e0e278515ea1e21e1e9537f079634413b9675357ac85e494
MD5 bc2cfdf1c62c1ce977d36e4435d3a680
BLAKE2b-256 20febae2d4ff47e5a419a5ad2e73bf584e6d9b4204281f05adb55a83cf26fe30

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