A simple-to-use Python package for time series anomaly detection!
Project description
Time Series Anomaly Detection
IMPORTANT:
dtaianomaly
is still a work in progress. Therefore, many changes are still expected. Feel free to contact us if there are any suggestions!
A simple-to-use Python package for the development and analysis of time series anomaly
detection techniques. Here we describe the main usage of dtaianomaly
, but be sure to
check out the documentation
for more information.
Installation
The easiest way to install the latest release of dtaianomaly
is through PyPi:
pip install dtaianomaly
Features
The three key features of dtaianomaly
are as follows:
- Large scale experiments. To evaluate anomaly detection methods, it is crucial to be able to perform large scale experiments. However, it is also crucial to ensure reproducibility of the obtained results. ´dtaianomaly´ provides a simple way to evaluate an anomaly detector on a large set of time sets. This allows to both (1) quantitatively evaluate the method by measuring the performance, runtime and memory usage, and (2) qualitatively evaluate the method by visually inspecting the detected anomalies. This is achieved by using configuration files, which ensure that identical settings are used for the experiments. We refer to the documentation for more details regarding how to set up and run experiments.
- Develop anomaly detectors. The models in
dtaianomaly
are all centered around theTimeSeriesAnomalyDetector
class, which provides an interface to detecting anomalies in time series. The main advantage of this abstract class is that anomaly detectors can be handled in an abstract manner. This allows to develop wrapper approaches around existing methods, without needing information about the specific algorithm. On top of this, by only implementing the interface ofTimeSeriesAnomalyDetector
, it is possible to develop new methods that can be used within the entire infrastructure ofdtaianomaly
. An example of how to implement a custom anomaly detector is given in this notebook. - Detect anomalies through a simple API. Once an anomaly detector is developed and
validated, it can be used to detect anomalies in time series.
dtaianomaly
provides a simple API (throughfit
andpredict
methods) to detect anomalies. The below code snippet illustrates how to detect anomalies in only a few lines of code. The complete example can be found in this notebook. The main advantage of ´dtaianomaly´ is that anomaly detectors can be used as a wrapper approach. Thus, you do not need to know anything about the ´TimeSeriesAnomalyDetector´ in order to detect anomalies.
from dtaianomaly.anomaly_detection import PyODAnomalyDetector, Windowing
trend_data = ... # Some time series as a numpy array of shape (n_samples, n_features)
# Initialize an IForest that takes as features each window of 100 observations
anomaly_detector = PyODAnomalyDetector('IForest', Windowing(window_size=100))
# Fit the anomaly detector
anomaly_detector.fit(trend_data)
# Compute the raw anomaly scores of an observation (in range [0, infinity])
raw_anomaly_scores = anomaly_detector.decision_function(trend_data)
# Compute the probability of an observation being an anomaly (in range [0, 1])
anomaly_probabilities = anomaly_detector.predict_proba(trend_data)
Examples
Several examples of how dtaianomaly
can be used are provided in the notebooks. Here
we list some of the most important ones to get to know dtaianomaly
:
- Quantitatively evaluate an anomaly detector: Shows how to quantitatively evaluate an anomaly detector on a benchmark set of time series.
- Custom anomaly detector: Illustrates a simple example
of a custom anomaly detector implemented in
dtaianomaly
. - PyOD anomaly detectors: Compares different anomaly detection algorithms implemented in the PyOD library, showing how you can use an anomaly detector as a wrapper approach.
Dependencies
Time series are represented as NumPy-arrays to detect anomalies, but can also be represented as Pandas DataFrames for visualization. Anomaly detection algorithms use the PyOD library. We use matplotlib for visualization.
dtaianomaly
also depends on scikit-learn and
scipy, but we plan on removing these dependencies in the near future.
Contact
Feel free to email to louis.carpentier@kuleuven.be if there are any questions, remarks, ideas, ...
License
Copyright (c) 2023 KU Leuven, DTAI Research Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dtaianomaly-0.1.1.tar.gz
.
File metadata
- Download URL: dtaianomaly-0.1.1.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e2c9ca630d381ba49c6b9acb4a08e4d31995b38566a211af6d57ec9ab74f30c |
|
MD5 | 824a89e233edcab7918be40b5359aaaa |
|
BLAKE2b-256 | 1edb379ab4b403ae6d1e5b0d47e7f7166d2bd241fcfd45f8331ec78952e05e7a |
File details
Details for the file dtaianomaly-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: dtaianomaly-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec3d797b336fc7ce22bc89f43a9a31908a807979f9667ec3a7515789251cde78 |
|
MD5 | 9b627ab1479978ea3b410e5fa897ccb7 |
|
BLAKE2b-256 | 174eea77eeec595c108fd4adaad7f45af4af7a4f0c894998cd7b7edd14036773 |