Giter Site home page Giter Site logo

crazybirl / vae-lstm-for-anomaly-detection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lin-shuyu/vae-lstm-for-anomaly-detection

0.0 0.0 0.0 2.06 MB

We propose a VAE-LSTM model as an unsupervised learning approach for anomaly detection in time series.

Jupyter Notebook 87.66% Python 12.34%

vae-lstm-for-anomaly-detection's Introduction

VAE-LSTM for anomaly detection (ICASSP'20)

This Github repository hosts our code and pre-processed data to train a VAE-LSTM hybrid model for anomaly detection, as proposed in our paper:

Anomaly Detection for Time Series Using VAE-LSTM Hybrid Model.
Shuyu Lin1, Ronald Clark2, Robert Birke3, Sandro Schönborn3, Niki Trigoni1, Stephen Roberts1
1University of Oxford, 2Imperial College London, 3ABB Corporate Research

In short, our anomaly detection model contains:

  • a VAE unit which summarizes the local information of a short window into a low-dimensional embedding,
  • a LSTM model, which acts on the low- dimensional embeddings produced by the VAE model, to manage the sequential patterns over longer term.

An overview of our model is shown below:

overview

An example of anomaly detection on a time series of office temperature, which is provided by Numenta anomaly benchmark (NAB) datasets in their known anomaly subgroup link:

result

To run our code, please follow the instructions shown below.

Environment

Our code is written in Python3 with tensorflow 1.5 library. Please install the python libraries listed in the requirements.txt. We suggest to build a virtual environment using virtualenv package. To install and set up virtualenv, please follwo the procedures here.

Data pre-processing

We pre-processed the NAB data, which consists of 5 sequences, by creating a training set that does not contain any anomalies while keeping the rest of sequence as test set for evaluation. In addition, we removed the mean and standardized the time series. Pre-processed data are included in the datasets/ subfolder with this repository for convenience of running our code. A demo ipython notebook has also been provided in datasets/ to show how the pre-processing is done. Explanation of the different features saved in the .npz files for the pre-processed datasets are given in the discussion.

If you want to use the data for your own project, please cite and refer to the NAB project and access the raw data if needed.

Training

Our VAE-LSTM model is defined in several files in the codes/ subfolder, including train.py, base.py, utils.py, data_loader.py, models.py, trainers.py. To train our model, simply run python3 train.py --config NAB_config.json, where NAB_config.json defines all the hyper-parameters of our model and you can experiment by using different values.

Anomaly detection using the trained model

After the model has been trained, we also prepare an iPython-notebook in NAB-anomaly-detection.ipynb for you to detect some anomalies detection on the test set. All you need to do is to run the code, make sure the NAB_config.json is prepared so that the right trained model will be loaded. The only thing that you need to specify in order to achieve reasonable anomaly detection result is to set a threshold on the anomaly detection metric. We suggest to observe the histogram of the anomaly detection metric and set the threshold accordingly.

Hope you enjoy playing with our code and find it helpful for your projects! Happy anomaly detection!

If you find our codes/project relevant to your work, please cite us in your work:

@INPROCEEDINGS{VAE-LSTM-AD, 
   author={S. {Lin} and R. {Clark} and R. {Birke} and S. {Schönborn} and N. {Trigoni} and S. {Roberts}}, 
   booktitle={ICASSP 2020 - 2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)}, 
   title={Anomaly Detection for Time Series Using VAE-LSTM Hybrid Model}, 
   year={2020}} 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.