Giter VIP home page Giter VIP logo

akash13singh / lstm_anomaly_thesis Goto Github PK

View Code? Open in Web Editor NEW
223.0 17.0 87.0 88.58 MB

Anomaly detection for temporal data using LSTMs

Home Page: http://kth.diva-portal.org/smash/record.jsf?pid=diva2%3A1149130&dswid=3326

License: MIT License

Python 0.18% Jupyter Notebook 99.82%
lstm anomaly-detection bayesian-optimization time-series recurrent-neural-networks deep-learning lstm-neural-networks neural-networks

lstm_anomaly_thesis's Introduction

Anomaly Detection for Temporal Data using LSTM.

This repository contains the code used in my master thesis on LSTM based anomaly detection for time series data. The thesis report can be downloaded from here.

Abstract

We explore the use of Long short-term memory (LSTM) for anomaly detection in temporal data. Due to the challenges in obtaining labeled anomaly datasets, an unsupervised approach is employed. We train recurrent neural networks (RNNs) with LSTM units to learn the normal time series patterns and predict future values. The resulting prediction errors are modeled to give anomaly scores. We investigate different ways of maintaining LSTM state, and the effect of using a fixed number of time steps on LSTM prediction and detection performance. LSTMs are also compared to feed-forward neural networks with fixed size time windows over inputs. Our experiments, with three real-world datasets, show that while LSTM RNNs are suitable for general purpose time series modeling and anomaly detection, maintaining LSTM state is crucial for getting desired results. Moreover, LSTMs may not be required at all for simple time series.

Requirements

  1. Keras 2.0.3
  2. TensorFlow 1.0.0
  3. sickit-learn 0.18.2
  4. GPyOpt 1.0.3. (only required for hyper-parameter tuning)

Configuration:

First set the configuration settings in configuration/config.py. This file has different configuration settings.

    1. Use `run_config` to set parameters for the program execution
     like data folder, log_file etc.
        * Xserver: denotes if the machine has a display environment. Set it to false when
                   running on remote machines with no display. Else the plotting comamnds will result in an error.
        * experiment_id: a id used to identify different runs for example in the logs. The result plots are saved in folder: imgs/<experiment_id>.

    2. Use `opt_congfig` to set parameters for optimization runs. Refer:
       [1](https://github.com/SheffieldML/GPyOpt) ,[2](http://pythonhosted.org/GPyOpt/)

    3. `multi_step_lstm_config`: contains parameters specific to LSTM network

For hyper-parameters used refer to table 4.1 in thesis reports.

How to Execute:

  1. Data Pre-processing: The LSTM network needs data formatted such that each input sample has look_back number of data points and each output sample has look_ahead number of time-steps. To convert the data into appropriate format and create train, test, and validation datasets python notebooks have been used. We provide notebooks for the three datasets used in the thesis which can be used as examples for new datasets. The three notebooks along with the processed dataset files are:
    1. ECG: notebooks/discords_ECG.ipynb, resources/data/discords/ECG/
    2. power_consumption: notebooks/discords_power_consumption.ipynb, resources/data/discords/dutch_power/
    3. machine_temperature: notebooks/NAB_machine_temp.ipynb, resources/data/nab/nab_machine_temperature/

This step is done in "Part 1" of corresponding notebook.

  1. Prediction Modeling: The main LSTM models used are in the file models/lstm.py. For training the model and generating predictions two main files are provided:

    1. lstm_predictor.py: This file uses the default LSTM implementation by keras.
    2. stateful_lstm_predictor.py: uses the stateful LSTM implementation

    Once the configuration setting data_folder has been set correctly, the code will look for train, test, and validation sets in those files.

  2. Anomaly Detection: Running the LSTM models which generate the predictions for train, test, and validation sets. For anomaly detection we need to calculate prediction errors or residuals, model them using Gaussian distribution and then set thresholds. This is done in "Part 3" of the corresponding notebook files.

lstm_anomaly_thesis's People

Contributors

akash13singh avatar deadskull7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lstm_anomaly_thesis's Issues

Doubts

Hello Akash. I've some questions for you...

  1. Is it possible to run this LSTM code with multi input parameters?
  2. The original parameters configuration is the one which have the best results?
  3. I don't understand why it returns me 2 very seimilar graphs everytime I run it in PyCharm, could u explain me?
  4. On this application it's only possible to run this project by manually labeling the anomalies in the dataset?

Thanks!

Cant find log file

whenever i run the lstm_predictor.py I am getting the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/home/sunjeet/lstm_anomaly_thesis-master/logs/run.log'

Its not able to find the log file. Can anyone help me resolve this.

Space Shuttle

Hi Akash!
I've read your report and likewise searched within the files and folders of "lstm_anomaly_thesis". the space shuttle dataset was trained and tested but it was not referenced anywhere in the thesis. what's the reason?

the "units" parameter

Hi! thank you for sharing this amazing code. I have one problem when I try to implement the code.
when I try to run these lines:
multistep_lstm = MultiStepLSTM(look_back=288, look_ahead=1,
layers={'input': 1, 'hidden1':120, 'output':1},
dropout=0.1, loss='mse',
learning_rate=0.02)
model = multistep_lstm.build_model()
it mentioned that: init() missing 1 required positional argument: 'units'

I see you set the self.layers['hidden1'] as units in the function called "StatefulMultiStepLSTM", but set the self.layers['hidden1'] as output_dim in the function"MultiStepLSTM".

can you help me with the missing argument problem?

LSTM on new Dataset

Hello Akashm first of all thank you for sharing your work with us, amazing documentation!
I'm trying to run the LSTM code for anomaly detection in my Dataset, but I'm not succeding... Could you give me a little help? My problem is that I dont know how to upload my own data.
I'm a new Python user...

Thanks in advance!

One question

Hi, recently, I am confused by whether the training set should include outliers, I saw you said you trained the normal time series data, I do not know the meaning of normal.

Please reply to me when you saw it,
Many Thanks,
Finn

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.