<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Active Learning for LSTM-autoencoder-based Anomaly Detection in Electrocardiogram Readings</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Tom´aˇs Sˇabata</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Martin Holenˇa</string-name>
          <email>martin@cs.cas.cz</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Information Technology, Czech Technical University in Prague</institution>
          ,
          <addr-line>Prague</addr-line>
          ,
          <country country="CZ">Czech Republic</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Institute of Computer Science of the Czech Academy of Sciences</institution>
          ,
          <addr-line>Prague</addr-line>
          ,
          <country country="CZ">Czech Republic</country>
        </aff>
      </contrib-group>
      <fpage>72</fpage>
      <lpage>77</lpage>
      <kwd-group>
        <kwd>Active Learning</kwd>
        <kwd>Anomaly detection</kwd>
        <kwd>LSTM-Autoencoder</kwd>
        <kwd>Time series</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Recently, the amount of generated time series data has been increasing rapidly
in many areas such as healthcare, security, meteorology and others. However, it
is very rare that those time series are annotated. For this reason, unsupervised
machine learning techniques such as anomaly detection are often used with such
data. There exist many unsupervised algorithms for anomaly detection ranging
from simple statistical techniques such as moving average or ARIMA till complex
deep learning algorithms such as LSTM-autoencoder. For a nice overview of the
recent algorithms we refer to read [
        <xref ref-type="bibr" rid="ref1 ref2">2,1</xref>
        ].
      </p>
      <p>Difficulties with the unsupervised approach are: defining an anomaly score to
correctly represent how anomalous is the time series, and setting a threshold for
that score to distinguish between normal and anomaly data. Supervised anomaly
detection, on the other hand, needs an expensive involvement of a human
expert. An additional problem with supervised anomaly detection is usually the
occurrence of very low ratio of anomalies, yielding highly imbalanced data.</p>
      <p>
        In this extended abstract, we propose an active learning extension for an
anomaly detector based on a LSTM-autoencoder. It performs active learning
using various classification algorithms and addresses data imbalance with
oversampling and under-sampling techniques. We are currently testing it on the
ECG5000 dataset from the UCR time series classification archive [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
      </p>
    </sec>
    <sec id="sec-2">
      <title>Active learning for LSTM-autonecoder-based anomaly detection</title>
      <p>
        LSTM-autoencoder [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] is nowadays increasingly used to detect anomalies in time
series data [
        <xref ref-type="bibr" rid="ref11 ref4 ref5">11,5,4</xref>
        ]. The algorithm aims to learn the identity function. It
consists of two parts – an encoder and a decoder. The encoder compresses the
© 2020 for this paper by its authors. Use permitted under CC BY 4.0.
input representation of the data into a low-dimensional latent representation
(usually called code) from which the decoder reconstructs the original input.
The model parameters are found by minimizing the reconstruction error.
Samples are then considered anomalous if their reconstruction error is higher than a
selected threshold.
      </p>
      <p>
        Although LSTM-autoencoder works well for time-series with complicated
patterns, setting the anomaly score threshold can be very complicated without
labelled data. Furthermore, with a higher ratio of anomalies present in the
training data, a simple setting of the threshold might produce a lot of false positives
and false negatives. Therefore, we incorporated active learning into building the
anomaly detector that uses the code of a previously trained LSTM autoencoder.
The most related research has been done by Pigmentel [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], who proposed to use a
classifier (logistic regression) with the latent layer of autoencoder together with
anomaly score. In contrast, we experiment with the latent layer of a recurrent
autoencoder without anomaly score and propose to use resampling techniques.
      </p>
      <p>
        First, an LSTM autoencoder is trained on unlabelled data. An initial anomaly
detection threshold on reconstruction error distribution is selected. At the initial
value of the threshold, we decided to use the mean plus three times the standard
deviation of the reconstruction error as an initial threshold. Every sample with
the reconstruction error above the threshold is labelled as an anomaly and the
same number of samples below the threshold are labelled as normal.
Furthermore, instead of the original time-series data, we use their representation in the
code layer. This provides us an artificially created, balanced dataset and
converts the anomaly detection to a binary classification task. A classifier is trained
on the created dataset and an active learning loop starts. In each iteration, a
resampler is used to balance the new updated labelled dataset. The resampler can
be either an undersampling or oversampling algorithm. The classifier is fitted
using the resampled data. Uncertainty sampling (US) active learning framework
[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] is used to select instances which should be labelled by an oracle. We use
margin US, i.e. we select instances leading to the smallest difference between
the likelihood of anomalous and normal data classes. Anomaly detection is then
based on predictions of that classifier instead of on the anomaly threshold. The
pseudo-code for the algorithm is shown in Algorithm 1.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Experiment and Results</title>
      <p>
        The proposed algorithm was evaluated on a benchmark time-series dataset with
electrocardiogram readings [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Each heart-beat record in the dataset is labelled
with one of 5 classes where the last three classes are very rare and we consider
them as an anomaly. The dataset was split into training, validation and testing in
the ratio 70:15:15. The validation dataset was used to find the hyperparameters
for the LSTM-autoencoder. The autoencoder achieving the lowest f1 score in the
anomaly detection on the validation data set was chosen. The final architecture
of the encoder consisted of two LSTM cells. The cells have one hidden layer with
48 neurons in the first cell and 24 neurons in the second cell. The hidden state
Algorithm 1: Active learning for LSTM-autoencoder anomaly detection
Input:
U : unlabelled data set of sequences
θ: anomaly score threshold
φ(·): query strategy utility function
begin
train LSTM autoencoder on data set U
// calculate anomaly scores
ai = |xi − decoder(encoder(xi))|, x ∈ U
sort a in the descending order
sort x respectively to a
i = 0, L = ∅
// Add anomalous data samples into the labelled dataset
while ai &gt; θ do
      </p>
      <p>L = L ∪ hencoder(xi), 1i
U = U \ xi
i = i + 1
end
// Add normal data samples into the labelled dataset
for j = i to 2i do</p>
      <p>L = L ∪ hencoder(xj), 0i</p>
      <p>U = U \ xj
end
while stopping criterion is not met do</p>
      <p>R = resampler(L)
train binary classifier m on R
// Find the most informative seqeuence from U and ask for label
x∗ = argmaxx∈U φ(x)
y∗ = query(x∗)
L = L ∪ hx∗, y∗i</p>
      <p>U = U \ x∗
end
end
of the last cell is copied and used as the input of the first cell of the decoder.
The decoder has architecture mirrored.</p>
      <p>
        We experimented with 5 classifiers: logistic regression, decision tree,
Gaussian naive Bayes classifier, k-nearest neighbours classifier and support vector
machines. We experimented with 11 under-sampling and 4 over-sampling
techniques taken from the imbalanced-learn python toolbox [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. In the presented
results, we report 5 under-sampling techniques that were best on average. In
the experiment, we compared a fully unsupervised approach, in which anomalies
are detected by using a chosen threshold, with our extension with respect to F1
score.
      </p>
      <p>
        Figure 1 shows how actively asking for annotations can improve the
unsupervised anomaly detection with an LSTM-autoencoder (red dashed line). The
best results were achieved with repeated edited nearest neighbours [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] and a
knearest neighbour classifier. However, using an SVM as the base classifier yielded
more stable performance.
      </p>
      <p>Moreover, a classifier model fed by labels outperformed the
LSTM-autoencoder with the initially set anomaly score threshold (red dashed line) and the
best possible anomaly score threshold (green dashed line). The source code is
available in GitHub repository 3.
4</p>
    </sec>
    <sec id="sec-4">
      <title>Conclusion</title>
      <p>We presented an active Learning for LSTM-autoencoder-based anomaly
detection for time-series data. An experiment on the ECG5000 data set has shown that
the proposed method is able to boost the performance of the model significantly
with only approximately 200 labelled samples. We plan next to experiment with
variational LSTM-autoencoders and to pay attention to the interpretability of
the detected anomalies .</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgements</title>
      <p>The work has been supported by the grant 18-18080S of the Czech Science
Foundation (GACˇ R).
3 https://github.com/tsabata/active_anomaly_detection
model_type = SVM
model_type = KNN
model_type = LogReg</p>
      <p>Fig. 1: F1 score performance metric in active learning loop. The figure contains 5
models (support vector machines (SVM), k-nearest neighbours (KNN), logistic
regression(LogReg), decision tree (DT) and Gaussian naive Bayes(GNB)) and
9 resampling techniques. The greyed area represents standard deviation. Red
dashed line represents the performance of the LSTM-autoencoder anomaly
detector without active learning and initial setting of the anomaly score threshold.
Green dashed line represent the performance of the LSTM-autoencoder anomaly
detector without active learning and the best setting of the anomaly score
threshold, and blue dashed line represents the best-achieved performance in the last
iteration of active learning loop.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Ahmad</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lavin</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Purdy</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Agha</surname>
            ,
            <given-names>Z.</given-names>
          </string-name>
          :
          <article-title>Unsupervised real-time anomaly detection for streaming data</article-title>
          .
          <source>Neurocomputing</source>
          <volume>262</volume>
          ,
          <fpage>134</fpage>
          -
          <lpage>147</lpage>
          (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Cook</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mısırlı</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fan</surname>
            ,
            <given-names>Z.</given-names>
          </string-name>
          :
          <article-title>Anomaly detection for iot time-series data: A survey</article-title>
          .
          <source>IEEE Internet of Things Journal</source>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Dau</surname>
            ,
            <given-names>H.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Keogh</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kamgar</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yeh</surname>
            ,
            <given-names>C.C.M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhu</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gharghabi</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ratanamahatana</surname>
            ,
            <given-names>C.A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yanping</surname>
            , Hu,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Begum</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bagnall</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mueen</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Batista</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <article-title>Hexagon-ML: The ucr time series classification archive</article-title>
          (
          <year>October 2018</year>
          ), https://www.cs.ucr.edu/~eamonn/time_series_data_2018/
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Ergen</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mirza</surname>
            ,
            <given-names>A.H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kozat</surname>
            ,
            <given-names>S.S.</given-names>
          </string-name>
          :
          <article-title>Unsupervised and semi-supervised anomaly detection with lstm neural networks</article-title>
          .
          <source>arXiv preprint arXiv:1710.09207</source>
          (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Guo</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Liao</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wang</surname>
            ,
            <given-names>Q.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Yu</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ji</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Li</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          :
          <article-title>Multidimensional time series anomaly detection: A gru-based gaussian mixture variational autoencoder approach</article-title>
          .
          <source>In: Asian Conference on Machine Learning</source>
          . pp.
          <fpage>97</fpage>
          -
          <lpage>112</lpage>
          (
          <year>2018</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6. Lemaˆıtre, G.,
          <string-name>
            <surname>Nogueira</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Aridas</surname>
            ,
            <given-names>C.K.</given-names>
          </string-name>
          :
          <article-title>Imbalanced-learn: A python toolbox to tackle the curse of imbalanced datasets in machine learning</article-title>
          .
          <source>The Journal of Machine Learning Research</source>
          <volume>18</volume>
          (
          <issue>1</issue>
          ),
          <fpage>559</fpage>
          -
          <lpage>563</lpage>
          (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Lewis</surname>
            ,
            <given-names>D.D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gale</surname>
            ,
            <given-names>W.A.</given-names>
          </string-name>
          :
          <article-title>A sequential algorithm for training text classifiers</article-title>
          .
          <source>In: SIGIR'94</source>
          . pp.
          <fpage>3</fpage>
          -
          <lpage>12</lpage>
          . Springer (
          <year>1994</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Pimentel</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Monteiro</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Viana</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Veloso</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ziviani</surname>
          </string-name>
          , N.:
          <article-title>A generalized active learning approach for unsupervised anomaly detection</article-title>
          .
          <source>stat 1050</source>
          ,
          <issue>23</issue>
          (
          <year>2018</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Srivastava</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mansimov</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Salakhudinov</surname>
          </string-name>
          , R.:
          <article-title>Unsupervised learning of video representations using lstms</article-title>
          .
          <source>In: International conference on machine learning</source>
          . pp.
          <fpage>843</fpage>
          -
          <lpage>852</lpage>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Tomek</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          , et al.:
          <article-title>An experiment with the edited nearest-nieghbor rule</article-title>
          .
          <source>IEEE Transactions on Systems, Man, and Cyberbetics 6</source>
          ,
          <fpage>448</fpage>
          -
          <lpage>452</lpage>
          (
          <year>1976</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Zhang</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chen</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          :
          <article-title>Time series anomaly detection with variational autoencoders</article-title>
          . arXiv preprint arXiv:
          <year>1907</year>
          .
          <volume>01702</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>