LSTM Autoencoder for Anamoly Detection

Adnan Karol
Analytics Vidhya
Published in
2 min readOct 14, 2020

Autoencoder has several applications like :

  1. Removal of Noise
  2. Feature extraction ( Use only Encoder part)
  3. Anomaly Detection

We are going to see the third application in very simple time-series data. The concept of Autoencoders can be applied to any Neural Network Architecture like DNN, LSTM, RNN, etc. Since we have time-series data we are going to design an LSTM Autoencoder.

The concept is simple we will train an autoencoder with simple (non-anomaly data). By doing this the Autoencoder can reconstruct back a known input sequence. And then when we have a sequence with has anomalies and are fed to the model then the model will try to reconstruct back the input, but the ERROR, in this case, will be high as the data has some features (anomalies) that the model is not trained to handle.

Please refer to my earlier blog here to structure the input, model, and the output.

This is supposed to be a continuation of the earlier blog.

As we are able to reconstruct back the original input. Let us check the Mean Square Error (MSE) of the Reconstructed Output with the Input.

Now Let us input a sequence that is close enough to input the model is trained with and check the MSE.

Finally, let's input a sequence with an anomaly i.e. with something that is not desirable.

Hence Using Autoencoder and the concept of Errors we can check for Anomalies in Data.

--

--