Anomaly detection module
This module contains functionality to detect anomalies. It can be imported as follows:
>>> from dtaianomaly import anomaly_detection
We refer to the documentation
for more information regarding detecting anomalies using dtaianomaly.
API cheatsheet
Below there is a quick overview of the most essential methods to detect anomalies:
fit(). Fit the anomaly detector. This method requires both anX(the time series) andy(anomaly labels) parameter. However, in practice, most anomaly detectors will not use the ground truth labels. The parameteryis present for API consistency and is not required.decision_function(). Compute the decision scores of an observation being an anomaly for a given time seriesX. Returns an array with an entry for each observation in the time series. Note that this score is not normalized, and depends on the specific anomaly detector. However, for all detectors, a higher score means more anomalous.predict_proba(). Compute the probability of an anomaly being an anomaly. This is similar to thedecision_function()method, but the computed scores are normalized to the interval \([0, 1]\), which enables the interpretation as a probability.Note
The output of a
predict_probais often a matrix of size(n_samples, n_classes). For anomaly detection, this would lead to a matrix with two columns, one columns for the normal probabilities and one column for the anomalous probabilities. However, indtaianomaly, thepredict_proba()only returns the probability of a sample being anomalous, because this is the probability of interest in many anomaly detection applications.
Base Objects
|
Abstract base class for time series anomaly detection. |
|
Base class for neural anomaly detectors, based on PyTorch. |
|
Base class for forecasting-based neural anomaly detectors. |
|
Base class for reconstruction-based neural anomaly detectors. |
|
Abstract class for anomaly detection based on the PyOD library [41]. |
|
Supervision types. |
|
Multivariate wrapper for anomaly detection. |
Utility functions
|
Load a detector from disk. |
Statistical methods
|
Anomaly detector based on the Cluster-based Local Outlier Factor (CBLOF) [15]. |
|
Copula-based outlier detector (COPD) algorithm [20]. |
|
Anomaly detector based on the Histogram Based Outlier Score (HBOS) algorithm [12]. |
|
Anomaly detector based on the Isolation Forest algorithm [22]. |
|
Anomaly detector based on the Kernel Principal Component Analysis (KPCA) [16]. |
|
Use KMeans clustering to detect anomalies [40]. |
|
Anomaly detector based on K-nearest neighbors [27]. |
|
Anomaly detector based on the Local Outlier Factor [5]. |
|
Anomaly detector based on One-Class Support Vector Machines (OC-SVM) [31]. |
|
Anomaly detector based on the Principal Component Analysis (PCA) [1]. |
|
Anomaly detection based on Robust Principal Component Analysis (Robust PCA) [6]. |
Time series statistical methods
|
Anomaly detection based on the Discrete Wavelet Transform [36]. |
|
Anomaly detector based on KShape-clustering [25]. |
|
Perform anomaly detection based on local polynomial approximations [21]. |
|
Anomaly detector based on the Matrix Profile [42]. |
|
Anomaly detection based on the Two-sided Median Method [3]. |
|
Detect anomalies using robust random cut forest [14]. |
|
Detect anomalies in time series subsequences with ROCKAD [35]. |
|
Detect anomalies using Spectral Residual [28]. |
Neural methods
|
Use an auto encoder to detect anomalies [30]. |
|
Use a convolutional neural network to detect anomalies. |
|
Anomaly detection based on a hybrid K-NN with AutoEncoder embedding [33]. |
|
Use an LSTM to detect anomalies [23]. |
|
Use a multilayer perceptron to detect anomalies. |
|
Use a transformer to detect anomalies [37]. |
Time series foundation models
|
Detect anomalies in time series using Chronos [2]. |
|
Detect anomalies in time series using MOMENT [13]. |
|
Detect anomalies using the Time-MoE foundation model [32]. |
Baselines
Detector that predicts all instances to be normal. |
|
Detector that predicts all instances to be anomalous. |
|
|
Detect anomalies based on the variance within a window. |
|
Assign random anomaly scores to the time series observations. |
|
Compute anomaly scores based on the squared difference. |