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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pyadts-0.0.1b0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file pyadts-0.0.1b0-py3-none-any.whl.

File metadata

  • Download URL: pyadts-0.0.1b0-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.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 3334755727f3dbac2fead1d1873644e539ab14164bf16dc75a8ea7edace8be36
MD5 639dd49629efca1da0cbdfc0bc460c98
BLAKE2b-256 5f8340f4fded80a2d04dc5850043c9e0d637b9e9a8face926c5268b279ee4561

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