Home

Awesome

<p align="center"> <img width="200" src="./assets/logo_TSB.png"/> </p> <h1 align="center">TSB-UAD</h1> <h2 align="center">An End-to-End Benchmark Suite for Univariate Time-Series Anomaly Detection</h2> <p> <img alt="PyPI - Downloads" src="https://pepy.tech/badge/tsb_uad"> <img alt="PyPI" src="https://img.shields.io/pypi/v/tsb-uad"> <img alt="License" src="https://img.shields.io/github/license/TheDatumOrg/tsb-uad"> <img alt="GitHub issues" src="https://img.shields.io/github/issues/TheDatumOrg/tsb-uad"> <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/tsb-uad"> <img alt="ReadTheDocs Status" src="https://readthedocs.org/projects/tsb-uad/badge/?version=latest"> </p> </div>

TSB-UAD is a new open, end-to-end benchmark suite to ease the evaluation of univariate time-series anomaly detection methods. Overall, TSB-UAD contains 12686 time series with labeled anomalies spanning different domains with high variability of anomaly types, ratios, and sizes. Specifically, TSB-UAD includes 18 previously proposed datasets containing 1980 time series from real-world data science applications. Motivated by flaws in certain datasets and evaluation strategies in the literature, we study anomaly types and data transformations to contribute two collections of datasets. Specifically, we generate 958 time series using a principled methodology for transforming 126 time-series classification datasets into time series with labeled anomalies. In addition, we present a set of data transformations with which we introduce new anomalies in the public datasets, resulting in 10828 time series (92 datasets) with varying difficulty for anomaly detection.

Quick start

Related Repository:

You can install TSB-UAD with pip (please read the installation section for more details).

pip install tsb-uad

If you use TSB-UAD in your project or research, cite the following papers:

References

"TSB-UAD: An End-to-End Benchmark Suite for Univariate Time-Series Anomaly Detection"<br/> John Paparrizos, Yuhao Kang, Paul Boniol, Ruey Tsay, Themis Palpanas, and Michael Franklin.<br/> Proceedings of the VLDB Endowment (PVLDB 2022) Journal, Volume 15, pages 1697–1711<br/>

@article{paparrizos2022tsb,
  title={Tsb-uad: an end-to-end benchmark suite for univariate time-series anomaly detection},
  author={Paparrizos, John and Kang, Yuhao and Boniol, Paul and Tsay, Ruey S and Palpanas, Themis and Franklin, Michael J},
  journal={Proceedings of the VLDB Endowment},
  volume={15},
  number={8},
  pages={1697--1711},
  year={2022},
  publisher={VLDB Endowment}
}

"Volume Under the Surface: A New Accuracy Evaluation Measure for Time-Series Anomaly Detection"<br/> John Paparrizos, Paul Boniol, Themis Palpanas, Ruey Tsay, Aaron Elmore, and Michael Franklin<br/> Proceedings of the VLDB Endowment (PVLDB 2022) Journal, Volume 15, pages 2774‑2787<br/>

@article{paparrizos2022volume,
  title={{Volume Under the Surface: A New Accuracy Evaluation Measure for Time-Series Anomaly Detection}},
  author={Paparrizos, John and Boniol, Paul and Palpanas, Themis and Tsay, Ruey S and Elmore, Aaron and Franklin, Michael J},
  journal={Proceedings of the VLDB Endowment},
  volume={15},
  number={11},
  pages={2774--2787},
  year={2022},
  publisher={VLDB Endowment}
}

"The Elephant in the Room: Towards A Reliable Time-Series Anomaly Detection Benchmark"<br/> Qinghua Liu and John Paparrizos<br/> NeurIPS 2024<br/>

@inproceedings{liu2024elephant,
  title={The Elephant in the Room: Towards A Reliable Time-Series Anomaly Detection Benchmark},
  author={Liu, Qinghua and Paparrizos, John},
  booktitle={NeurIPS 2024},
  year={2024}
}

Contributors

Installation

The following tools are required to install TSB-UAD from source:

Steps

  1. First, due to limitations in the upload size on GitHub, we host the datasets at a different location. Please download the datasets using the following links:

❗️Exciting Update: Public v2 is now available, featuring 29 datasets and 3,427 time series! Download it here: https://www.thedatum.org/datasets/TSB-UAD-Public-v2.zip

  1. Clone this repository using git and change into its root directory.
git clone https://github.com/TheDatumOrg/TSB-UAD.git
cd TSB-UAD/
  1. Create and activate a conda-environment 'TSB'.
conda env create --file environment.yml
conda activate TSB
  1. Install the dependencies from requirements.txt:
pip install -r requirements.txt
  1. Install TSB-UAD:

You can install TSB-UAD with pip.

pip install TSB-UAD

Please note that NormA and Series2Graph are not available on the pip package. To use them, please unlock the corresponding zip files and install the package locally:

pip install .

Benchmark

All are datasets and time series are stored in ./data. We describe below the different types of datasets used in our benchmark.

Benchmark: Public Real Datasets

We first collected 18 public datasets from heterogeneous domains (you may find them in benchmark/). The figure below shows some typical outliers in these 18 datasets.

<p align="center"> <img width="1000" src="./assets/figures_data/display_data.jpg"/> </p>

Briefly, TSB-UAD includes the following datasets:

DatasetDescription
Dodgersis a loop sensor data for the Glendale on-ramp for the 101 North freeway in Los Angeles and the anomalies represent unusual traffic after a Dodgers game.
ECGis a standard electrocardiogram dataset and the anomalies represent ventricular premature contractions. We split one long series (MBA_ECG14046) with length ∼ 1e7) to 47 series by first identifying the periodicity of the signal.
IOPSis a dataset with performance indicators that reflect the scale, quality of web services, and health status of a machine.
KDD21is a composite dataset released in a recent SIGKDD 2021 competition with 250 time series.
MGABis composed of Mackey-Glass time series with non-trivial anomalies. Mackey-Glass time series exhibit chaotic behavior that is difficult for the human eye to distinguish.
NABis composed of labeled real-world and artificial time series including AWS server metrics, online advertisement clicking rates, real time traffic data, and a collection of Twitter mentions of large publicly-traded companies.
NASA-SMAP and NASA-MSLare two real spacecraft telemetry data with anomalies from Soil Moisture Active Passive (SMAP) satellite and Curiosity Rover on Mars (MSL). We only keep the first data dimension that presents the continuous data, and we omit the remaining dimensions with binary data.
SensorScopeis a collection of environmental data, such as temperature, humidity, and solar radiation, collected from a typical tiered sensor measurement system.
YAHOOis a dataset published by Yahoo labs consisting of real and synthetic time series based on the real production traffic to some of the Yahoo production systems.
Daphnetcontains the annotated readings of 3 acceleration sensors at the hip and leg of Parkinson’s disease patients that experience freezing of gait (FoG) during walking tasks.
GHLis a Gasoil Heating Loop Dataset and contains the status of 3 reservoirs such as the temperature and level. Anomalies indicate changes in max temperature or pump frequency.
Genesisis a portable pick-and-place demonstrator which uses an air tank to supply all the gripping and storage units.
MITDBcontains 48 half-hour excerpts of two-channel ambulatory ECG recordings, obtained from 47 subjects studied by the BIH Arrhythmia Laboratory between 1975 and 1979.
OPPORTUNITY (OPP)is a dataset devised to benchmark human activity recognition algorithms (e.g., classiffication, automatic data segmentation, sensor fusion, and feature extraction). The dataset comprises the readings of motion sensors recorded while users executed typical daily activities.
Occupancycontains experimental data used for binary classiffication (room occupancy) from temperature, humidity, light, and CO2. Ground-truth occupancy was obtained from time stamped pictures that were taken every minute.
SMD (Server Machine Dataset)is a 5-week-long dataset collected from a large Internet company. This dataset contains 3 groups of entities from 28 different machines.
SVDBincludes 78 half-hour ECG recordings chosen to supplement the examples of supraventricular arrhythmias in the MIT-BIH Arrhythmia Database.

The following table summarizes different characteristics of the datasets.

DatasetCountAverage lengthAverage number of anomaliesAverage number of abnormal points
Dodger150400.0133.05612
ECG53230351.9195.615634
IOPS58102119.246.52312.3
KDD2125077415.061.0196.5
MGAB10100000.010.0200.0
NAB586301.72.0575.5
SensorScope2327038.411.26110.4
YAHOO3671561.25.910.7
NASA-MSL272730.71.33286.3
NASA-SMAP548066.01.261032.4
Daphnet4521760.07.62841.0
GHL126200001.01.2388.8
Genesis616220.03.050.0
MITDB32650000.0210.172334.3
OPP46531616.92.01267.3
Occupancy105725.818.31414.5
SMD28125562.310.4900.2
SVDB115230400.0208.027144.5

You may find more details (and the references) in our paper.

Benchmark: Synthetic and Artificial Datasets

We also include synthetic and artifical datasets. We construct and transformed dataset based on the UCR archive (you may find them in UCR2018-NEW/ which contains 128 subfolders). The synthetic and artifical datasets are stored here:

<p align="center"> <img width="500" src="./assets/figures_data/transform_subsequence.png"/> </p> <p align="center"> <img width="500" src="./assets/figures_data/transform_global.png"/> </p> <p align="center"> <img width="500" src="./assets/figures_data/transform_local.png"/> </p>

Anomaly Detectors

We use 13 anomaly detection methods proposed for univariate time series. the following table lists and describes the methods considered in our benchmark:

<p align="center"> <img width="1000" src="./assets/taxonomy_short.png"/> </p>
Anomaly Detection MethodDescription
Isolation Forest (IForest)This method constructs the binary tree based on the space splitting and the nodes with shorter path lengths to the root are more likely to be anomalies.
The Local Outlier Factor (LOF)This method computes the ratio of the neighboring density to the local density.
The Histogram-based Outlier Score (HBOS)This method constructs a histogram for the data and the inverse of the height of the bin is used as the outlier score of the data point.
Matrix Profile (MP)This method calculates as anomaly the subsequence with the most significant 1-NN distance.
NORMAThis method identifies the normal pattern based on clustering and calculates each point's effective distance to the normal pattern.
Principal Component Analysis (PCA)This method projects data to a lower-dimensional hyperplane, and data points with a significant distance from this plane can be identified as outliers.
Autoencoder (AE)This method projects data to the lower-dimensional latent space and reconstructs the data, and outliers are expected to have more evident reconstruction deviation.
LSTM-ADThis method build a non-linear relationship between current and previous time series (using Long-Short-Term-Memory cells), and the outliers are detected by the deviation between the predicted and actual values.
Polynomial Approximation (POLY)This method build a non-linear relationship between current and previous time series (using polynomial decomposition), and the outliers are detected by the deviation between the predicted and actual values.
CNNThis method build a non-linear relationship between current and previous time series (using convolutional Neural Network), and the outliers are detected by the deviation between the predicted and actual values.
One-class Support Vector Machines (OCSVM)This method fits the dataset to find the normal data's boundary.
Discord Aware Matrix Profile (DAMP)This method is a scalable matrix Profile-based approach proposed to solves the twin-freak problem.
SANDThis method identifies the normal pattern based on clustering updated through arriving batches (i.e., subsequences) and calculates each point's effective distance to the normal pattern. This method can be used either online and offline.
Series2GraphThis method is converting the time series into a directed graph reprenting the evolution of subsequences in time. The anomalies are detected using the weight and the degree of the nodes and edges respectively.

You may find more details (and the references) in our paper. In italics are methods that are available but not evaluated yet.

Overall Results

We report in the following table the average AUC-ROC and F score for each method on each dataset. The accuracy scores are averaged for all the time series in each dataset.

DatasetsIForestIForest1LOFMPPCANORMAHBOSPOLYOCSVMAECNNLSTM
AUCFAUCFAUCFAUCFAUCFAUCFAUCFAUCFAUCFAUCFAUCFAUCF
Dodgers0.790.160.640.020.540.100.520.190.770.260.790.190.30.000.690.100.640.000.730.080.680.060.390.04
ECG0.750.270.610.180.560.090.580.120.710.250.950.330.680.200.700.240.640.170.730.210.520.030.540.03
IOPS0.540.040.780.250.500.080.720.100.740.170.760.120.640.110.680.110.710.140.630.130.610.090.610.10
MGAB0.570.000.580.000.960.620.910.240.540.000.550.000.540.000.510.000.520.000.710.060.580.040.560.03
NAB0.450.050.560.100.480.070.490.050.690.160.580.050.680.110.750.140.610.090.540.070.520.060.500.05
NASA-MSL0.570.040.690.210.520.030.520.000.750.230.550.000.770.210.810.240.640.120.700.140.570.140.570.13
NASA-SMAP0.720.210.680.130.680.200.620.180.740.250.800.190.770.270.800.200.650.310.770.330.680.170.640.14
SensorScope0.560.000.560.060.550.090.500.020.540.050.590.010.560.020.620.090.510.040.520.030.520.040.530.05
YAHOO0.620.060.810.180.860.110.860.060.570.060.920.110.570.070.760.080.500.030.790.060.960.470.940.46
KDD210.650.090.570.020.780.170.900.220.580.070.880.220.600.060.580.040.600.160.790.160.740.120.660.08
Daphnet0.740.060.680.080.780.080.440.000.690.050.460.000.690.040.770.080.450.010.440.010.470.010.440.02
GHL0.940.070.940.060.540.000.420.010.910.020.640.000.920.020.760.020.450.020.630.010.470.000.470.00
Genesis0.780.000.660.190.680.000.350.000.850.000.60.000.590.000.870.320.700.030.720.010.730.020.530.01
MITDB0.700.090.610.060.610.090.690.110.670.090.860.200.700.070.680.110.650.130.800.170.580.050.510.02
OPP0.490.070.520.030.450.100.820.010.520.150.650.060.540.090.280.010.380.010.700.070.470.010.570.08
Occupancy0.860.030.780.070.530.040.320.000.780.080.530.000.890.020.800.130.660.020.690.020.790.040.710.02
SMD0.850.350.730.250.690.180.510.030.800.310.610.030.770.310.870.410.610.110.630.090.610.080.580.07
SVDB0.720.190.580.080.590.140.740.170.680.190.920.330.710.150.670.180.680.150.790.180.580.070.550.06

Here we only report the average accuracy (AUC-ROC and F score) for each dataset. You may find here the accuracy tables for each time series and each accuracy measure.

We then compare the accuracy scores of the anoamly detection methods on time series containing point versus sequence anomalies and a single versus multiple anomalies. The following figure summarize the results:

<p align="center"> <img width="1000" src="./assets/figures_results/all_results.jpg"/> </p>

This figure and many others comparisons are described (and reproductible) in this notebook, summarized in this assetsument. The scripts to reproduce the critical diagrams and the statistical tests are here.

Usage

Anomaly Detector

We depicts below a code snippet demonstrating how to use one anomaly detector (in this example, IForest).

import os
import numpy as np
import pandas as pd
from TSB_UAD.models.iforest import IForest
from TSB_UAD.models.feature import Window
from TSB_UAD.utils.slidingWindows import find_length
from TSB_UAD.vus.metrics import get_metrics

df = pd.read_csv('data/benchmark/ECG/MBA_ECG805_data.out', header=None).to_numpy()
data = df[:, 0].astype(float)
label = df[:, 1]

slidingWindow = find_length(data)
X_data = Window(window = slidingWindow).convert(data).to_numpy()

clf = IForest(n_jobs=1)
clf.fit(X_data)
score = clf.decision_scores_

score = MinMaxScaler(feature_range=(0,1)).fit_transform(score.reshape(-1,1)).ravel()
score = np.array([score[0]]*math.ceil((slidingWindow-1)/2) + list(score) + [score[-1]]*((slidingWindow-1)//2))


results = get_metrics(score, label, metric="all", slidingWindow=slidingWindow)
for metric in results.keys():
    print(metric, ':', results[metric])
AUC_ROC : 0.9216216369841076
AUC_PR : 0.6608577550833885
Precision : 0.7342093339374717
Recall : 0.4010891089108911
F : 0.5187770129662238
Precision_at_k : 0.4010891089108911
Rprecision : 0.7486112853253205
Rrecall : 0.3097733542316151
RF : 0.438214653167952
R_AUC_ROC : 0.989123018780308
R_AUC_PR : 0.9435238401582703
VUS_ROC : 0.9734357459251715
VUS_PR : 0.8858037295594041
Affiliation_Precision : 0.9630674176380548
Affiliation_Recall : 0.9809813654809071

You may find more details on how to run each anomaly detection method in this notebook and this script.

Build Artifical Dataset

You may find details and examples on how to create artifical datasets in this notebook and this script

Apply Transformations to a Dataset

You may find details and examples on how to apply transformations on a dataset in this notebook and this script