Retour au classement

chickenbestlover/RNN-Time-series-Anomaly-Detection

Python

RNN based Time-series Anomaly detector model implemented in Pytorch.

rnnneural-networkanomaly-detectiontime-seriespredictionforecast
Croissance des étoiles
Étoiles
1.3k
Forks
310
Croissance hebdomadaire
Issues
34
5001k
janv. 2023mars 2024mai 2025juil. 2026
ArtefactsPyPIpip install rnn-time-series-anomaly-detection
README

RNN-Time-series-Anomaly-Detection

RNN based Time-series Anomaly detector model implemented in Pytorch.

This is an implementation of RNN based time-series anomaly detector, which consists of two-stage strategy of time-series prediction and anomaly score calculation.

Requirements

  • Ubuntu 16.04+ (Errors reported on Windows 10. see issue. Suggesstions are welcomed.)
  • Python 3.5+
  • Pytorch 0.4.0+
  • Numpy
  • Matplotlib
  • Scikit-learn

Dataset

1. NYC taxi passenger count

2. Electrocardiograms (ECGs)

  • The ECG dataset containing a single anomaly corresponding to a pre-ventricular contraction

3. 2D gesture (video surveilance)

  • X Y coordinate of hand gesture in a video

4. Respiration

  • A patients respiration (measured by thorax extension, sampling rate 10Hz)

5. Space shuttle

  • Space Shuttle Marotta Valve time-series

6. Power demand

  • One years power demand at a Dutch research facility

The Time-series 2~6 are provided by E. Keogh et al. in "HOT SAX: Efficiently Finding the Most Unusual Time Series Subsequence." In The Fifth IEEE International Conference on Data Mining. (2005) , dataset

DISCLAIMER:

The labels provided on this repository are unofficial and have not been verified. Labels were unofficially created by non-experts (annotated without any domain knowledge of the dataset or access to out-of-band data that could confirm the labels) and may contain mislabeled points (both false negatives, and false posatives). We referred to other time-series anomaly detection papers using the datasets (Malhotra et al., 2015., Malhotra et al., 2016.) and the author's dataset presentation slides to label anomaly points in this time series as accurately as possible. If you need accurate label information, you should refer to the official dataset description or contact the authors.

RNN-based Multi-Step Prediction Model

0. Architecture

arch

When the value of x_i is known from i=0 to i=t, the model recursively predicts the value of x_i from i=t+1 to i=T. In this figure, t=3, T=8. We first train this model with a trainset which contains no anomalies, then we use the trained model to detect anomalies in a testset, where anomalies are included.

1. How to train this model

Recursive multi-step prediction using RNNs is a rather difficult problem. As the prediction progresses, the prediction errors are accumulated and the predictions rapidly become inaccurate. To solve this problem, we need a model that is robust to input noise.

1steploss

TODO

msteploss

TODO

pfloss

TODO

RNN-based Multi-Step Prediction Model

TODO

Example of usage

0. Download the dataset: Download the five kinds of multivariate time-series dataset (ecg, gesture,power_demand, respiration, space_shuttle), and Label all the abnormality points in the dataset.

    python 0_download_dataset.py

1. Time-series prediction: Train and save RNN based time-series prediction model on a single time-series trainset

    python 1_train_predictor.py --data ecg --filename chfdb_chf14_45590.pkl
    python 1_train_predictor.py --data nyc_taxi --filename nyc_taxi.pkl

Train multiple models using bash script

    ./1_train_predictor_all.sh

2. Anomaly detection: Fit multivariate gaussian distribution and calculate anomaly scores on a single time-series testset

    python 2_anomaly_detection.py --data ecg --filename chfdb_chf14_45590.pkl --prediction_window 10
    python 2_anomaly_detection.py --data nyc_taxi --filename nyc_taxi.pkl --prediction_window 10

Test multiple models using bash script

    ./2_anomaly_detection_all.sh

Result

1. Time-series prediction: Predictions from the stacked RNN model

prediction1

prediction2

2. Anomaly detection:

Anomaly scores from the Multivariate Gaussian Distribution model

equation1

  • NYC taxi passenger count

scores1

  • Electrocardiograms (ECGs) (filename: chfdb_chf14_45590)

scores3

scores4

Evaluation

Model performance was evaluated by comparing the model output with the pre-labeled ground-truth. Note that the labels are only used for model evaluation. The anomaly score threshold was increased from 0 to some maximum value to plot the change of precision, recall, and f1 score. Here we show only the results for the ECG dataset. Execute the code yourself and see more results.

1. Precision, recall, and F1 score:

  • Electrocardiograms (ECGs) (filename: chfdb_chf14_45590)

a. channel 0

f1ecg1

b. channel 1

f1ecg2

Citations

Please consider citing this project in your publications if it helps your research. The following is a BibTeX reference. The BibTeX entry requires the url LaTeX package.

@misc{park2018anomaly,
author = {Park, Jinman},
title = {{RNN based Time-series Anomaly Detector Model Implemented in Pytorch}},
year = {2018},
howpublished = {\url{https://github.com/chickenbestlover/RNN-Time-series-Anomaly-Detection}},
note = {Accessed: [Insert date here]}
}

References

Contact

If you have any questions, please open an issue.

Dépôts similaires
microsoft/AI-For-Beginners

12 Weeks, 24 Lessons, AI for All!

Jupyter NotebookMIT Licensedeep-learningartificial-intelligence
52.5k10.6k
apachecn/ailearning

AiLearning:数据分析+机器学习实战+线性代数+PyTorch+NLTK+TF2

PythonPyPIOtherfp-growthapriori
ailearning.apachecn.org
42.4k11.5k
Mikoto10032/DeepLearning

深度学习入门教程, 优秀文章, Deep Learning Tutorial

Jupyter NotebookApache License 2.0deeplearningcnn
17.6k3.9k
datawhalechina/leedl-tutorial

《李宏毅深度学习教程》(李宏毅老师推荐👍,苹果书🍎),PDF下载地址:https://github.com/datawhalechina/leedl-tutorial/releases

Jupyter NotebookOthermachine-learningdeep-learning
16.7k3.1k
BlinkDL/RWKV-LM

RWKV (pronounced RwaKuv) is an RNN with great LLM performance, which can also be directly trained like a GPT transformer (parallelizable). We are at RWKV-7 "Goose". So it's combining the best of RNN and transformer - great performance, linear time, constant space (no kv-cache), fast training, infinite ctx_len, and free sentence embedding.

PythonPyPIApache License 2.0attention-mechanismdeep-learning
14.6k1k
BlinkDL/ChatRWKV

ChatRWKV is like ChatGPT but powered by RWKV (100% RNN) language model, and open source.

PythonPyPIApache License 2.0chatbotchatgpt
9.5k683
MorvanZhou/PyTorch-Tutorial

Build your neural network easy and fast, 莫烦Python中文教学

Jupyter NotebookMIT Licenseneural-networkpython
mofanpy.com/tutorials/machine-learning/torch/
8.5k3.1k
nfmcclure/tensorflow_cookbook

Code for Tensorflow Machine Learning Cookbook

Jupyter NotebookMIT Licensetensorflowtensorflow-cookbook
packtpub.com/big-data-and-business-intelligence/tensorflow-machine-learning-cookbook-second-edition
6.2k2.4k
timeseriesAI/tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai

Jupyter NotebookApache License 2.0time-series-classificationdeep-learning
timeseriesai.github.io/tsai/
6.1k720
xiph/rnnoise

Recurrent neural network for audio noise reduction

CBSD 3-Clause "New" or "Revised" Licensernnnoise-reduction
5.7k1.1k
bentrevett/pytorch-seq2seq

Tutorials on implementing a few sequence-to-sequence (seq2seq) models with PyTorch and TorchText.

Jupyter NotebookMIT Licensepytorchseq2seq
5.7k1.4k
grobidOrg/grobid

A machine learning software for extracting information from scholarly documents

JavaMavenApache License 2.0machine-learningscientific-articles
grobid.readthedocs.io
5k561