Skip to main content

A python package for time series anomaly detection

Project description

Anomaly Detection for Time-series (PyADTS)

Build Status Coverage Status Documentation Status PyPI Anaconda Code style: black Binder

PyADTS is aimed at accelerating the workflow of time series anomaly detection for researchers. It contains various utilities for data loading, pre-processing, detector construction, detector ensemble, evaluation and etc. PyADTS can help you to write less boilerplate on following parts:

  • Preparing dataset & pre-processing
  • Feature extraction (Optional)
  • Model training
  • Ensemble (Optional)
  • Evaluation

You can find the complete documentation here.

Table of Contents:

Installation

To install the package locally, run:

>> cd <pyadts_dir>
>> pip install .

To install the package from PyPi, run:

>> pip install pyadts

Quick Start

Fetch the dataset

PyADTS contains various built-in datasets. To utilize them:

from pyadts.data import get_nab_nyc_taxi

data = get_nab_nyc_taxi(root_path='<the_path_of_nab_dataset>')

All components of the dataset are organized as a dict:

{'value': value, 'label': label, 'timestamp': timestamp, 'datetime': datetime}

Pre-processing

It's important to pre-process the time series before training. PyADTS offered three types of pre-processing methods including:

  • Rearrangement: Sort the values along with the timestamp and reconstruct the timestamp to discover missing values. (return a dict and append an attribute missing)
  • Normalization: Normalize the time series
  • Imputation: Impute the time series.
from pyadts.data import series_impute, series_normalize, series_rearrange

data_processed = series_rearrange(**data)

data_processed['value'] = series_normalize(data_processed['value'], mask=data_processed['missing'], method='zscore')

data_processed['value'] = series_impute(data_processed['value'], missing=data_processed['missing'], method='linear')

Feature extraction

Extracting manual features is essential for some anomaly detection approaches. PyADT offered various options for extracting features including:

  • Simple features: logarithm, difference, second-order difference, ...
  • Window-based features: window mean value, window std value, ...
  • Decomposition features: STL decomposition, ...
  • Frequency domain features: wavelet features, spectral residual, ...
  • Regression features: SARIMA regression residual, Exponential Smoothing residual, ...
from pyadts.data import FeatureExtractor

feature_extractor = FeatureExtractor()

Train the model

Different anomaly detection algorithms should be utilized to tackle different scenarios. PyADT contains various algorithms including supervised-, unsupervised-, nonparametric-methods (you can refer the full list of implemented algorithms).

from pyadts import ThresholdDetector

train_x = data['value']
detector = ThresholdDetector()
pred_y = detector.fit_predict(train_x)

Ensemble

TODO

Evaluation

It's easy to evaluate your algorithms using PyADT's built-in metrics:

from pyadts import roc_auc

train_y = data['label']
roc = roc_auc(pred_y, train_y, delay=7)

In real-world applications, the delay of anomaly alerts is acceptable. So PyADT offered the delay argument for all metrics.

The pipeline

TODO

Other Utilities

Visualization

You can visualize your data with a single line of code:

from pyadts.data import plot_series

fig = plot_series(value=data['value'], label=data['label'], datetime=data['datetime'], plot_vline=True)
fig.show()

The example visualization:

Generate synthetic data

TODO

Implemented Algorithms

Supervised Approaches

  • Random Forest
  • SVM
  • Deep Neural Network

Unsupervised Approaches

Non-parametric

  • SR
  • Threshold
  • Quantile
  • K​-Sigma

Statistic-based

  • SPOT
  • DSPOT
  • Autoregression
  • ESD
  • S-ESD
  • S-H-ESD

Machine learning-based

  • LOF
  • Isolation Forest
  • OCSVM

Deep-based

  • Autoencoder
  • RNN Autoencoder
  • Donut

TODO

  • Fix bugs and reformat code
  • Multi-variate time series support
  • Complete the models
  • Incorporating Numba
  • Implement the pipeline
  • Synthetic data generator
  • Allow both inplace and non-inplace operations
  • Add streaming support

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

pyadts-0.0.2a0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyadts-0.0.2a0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file pyadts-0.0.2a0.tar.gz.

File metadata

  • Download URL: pyadts-0.0.2a0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pyadts-0.0.2a0.tar.gz
Algorithm Hash digest
SHA256 d107496c1362344c51737dc5297d483d591222216dd8bdf161b8433c949496ed
MD5 309ba67e12d461165f20b6ff5d44ca36
BLAKE2b-256 81f7f451729ce4c75051b9905bdcb63fbf22dc082667b31fc06dc00db18fe310

See more details on using hashes here.

File details

Details for the file pyadts-0.0.2a0-py3-none-any.whl.

File metadata

  • Download URL: pyadts-0.0.2a0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pyadts-0.0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ddd2fbbba2f4e003ec3d682b740a0fc8f93b3bbbd9982430b50e05c3ed457fe
MD5 96f11e9240e2153ee51c3e1d945aaaf9
BLAKE2b-256 f7120eebd2ff373272148133c2af37c15754e0d7d97bdb91b2655add428e79ad

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