Skip to main content

Precision and Recall for Time Series

License Python package PyPI version

Unofficial python implementation of Precision and Recall for Time Series.

Classical anomaly detection is principally concerned with point-based anomalies, those anomalies that occur at a single point in time. Yet, many real-world anomalies are range-based, meaning they occur over a period of time. Motivated by this observation, we present a new mathematical model to evaluate the accuracy of time series classification algorithms. Our model expands the well-known Precision and Recall metrics to measure ranges, while simultaneously enabling customization support for domain-specific preferences.

This is the open source software released by Computational Mathematics Laboratory. It is available for download on PyPI.

Installation

PyPI

PRTS is on PyPI, so you can use pip to install it.

$ pip install prts

from github

You can also use the following command to install.

$ git clone https://github.com/CompML/PRTS.git
$ cd PRTS
$ make install  # (or make develop)

Usage

from prts import ts_precision, ts_recall


# calculate time series precision score
precision_flat = ts_precision(real, pred, alpha=0.0, cardinality="reciprocal", bias="flat")
precision_front = ts_precision(real, pred, alpha=0.0, cardinality="reciprocal", bias="front")
precision_middle = ts_precision(real, pred, alpha=0.0, cardinality="reciprocal", bias="middle")
precision_back = ts_precision(real, pred, alpha=0.0, cardinality="reciprocal", bias="back")
print("precision_flat=", precision_flat)
print("precision_front=", precision_front)
print("precision_middle=", precision_middle)
print("precision_back=", precision_back)

# calculate time series recall score
recall_flat = ts_recall(real, pred, alpha=0.0, cardinality="reciprocal", bias="flat")
recall_front = ts_recall(real, pred, alpha=0.0, cardinality="reciprocal", bias="front")
recall_middle = ts_recall(real, pred, alpha=0.0, cardinality="reciprocal", bias="middle")
recall_back = ts_recall(real, pred, alpha=0.0, cardinality="reciprocal", bias="back")
print("recall_flat=", recall_flat)
print("recall_front=", recall_front)
print("recall_middle=", recall_middle)
print("recall_back=", recall_back)

Parameters

Parameter Description Type
alpha Relative importance of existence reward (0 ≤ alpha ≤ 1). float
cardinality Cardinality type. This should be "one", "reciprocal" or "udf_gamma" string
bias Positional bias. This should be "flat", "front", "middle", or "back" string

Examples

We provide a simple example code. By the following command you can run the example code for the toy dataset and visualize the metrics.

$ python3 examples/precision_recall_for_time_series.py

example output

Tests

You can run all the test codes as follows:

$ make test

References

  • Tatbul, Nesime, Tae Jun Lee, Stan Zdonik, Mejbah Alam, and Justin Gottschlich. 2018. “Precision and Recall for Time Series.” In Advances in Neural Information Processing Systems, edited by S. Bengio, H. Wallach, H. Larochelle, K. Grauman, N. Cesa-Bianchi, and R. Garnett, 31:1920–30. Curran Associates, Inc.

LICENSE

This repository is Apache-style licensed, as found in the LICENSE file.

Citation

@software{https://doi.org/10.5281/zenodo.4428056,
  doi = {10.5281/ZENODO.4428056},
  url = {https://zenodo.org/record/4428056},
  author = {Ryohei Izawa, Ryosuke Sato, Masanari Kimura},
  title = {PRTS: Python Library for Time Series Metrics},
  publisher = {Zenodo},
  year = {2021},
  copyright = {Open Access}
}

Metadata

Release files for prts 1.0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prts 1.0.0.3
File Size Uploaded
prts-1.0.0.3.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prts 1.0.0.3
File Interpreter ABI Platform
prts-1.0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / prts-1.0.0.3.tar.gz

Download URL prts-1.0.0.3.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
82baa65f3f121688e2b838b8512e6bd5d3b854bb1dcfae7dced7d78cffc095db
BLAKE2b-256 checksum
How to use checksums
15f72ba5af48ac7df243840dc36212690800b5eb360ad2545fe511ff1a095439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.3 Darwin/19.6.0

Release files / prts-1.0.0.3-py3-none-any.whl

Download URL prts-1.0.0.3-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71646a19610fb8693ba9d8939fd23f5de4c3c79bbc137e6d9bc68984a8be49dd
BLAKE2b-256 checksum
How to use checksums
9b1e75611b63f0b43008f37079eb9e7614fb2282af55d391ccbb6e98aa380495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.3 Darwin/19.6.0

Release history Release notifications | RSS feed

This release

1.0.0.3 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page