【问题标题】:Understand the output of LSTM autoencoder and use it to detect outliers in a sequence了解 LSTM 自编码器的输出并用它来检测序列中的异常值
【发布时间】:2020-08-27 05:13:52
【问题描述】:

我尝试构建 LSTM 模型,该模型作为输入接收整数序列并输出每个整数出现的概率。如果这个概率很低,那么这个整数应该被认为是异常的。我尝试遵循本教程 - https://towardsdatascience.com/lstm-autoencoder-for-extreme-rare-event-classification-in-keras-ce209a224cfb,尤其是我的模型来自的地方。我的输入如下所示:

[[[3]
  [1]
  [2]
  [0]]

 [[3]
  [1]
  [2]
  [0]]

 [[3]
  [1]
  [2]
  [0]]

但是我无法理解我作为输出获得了什么。

[[[ 2.7052343 ]
  [ 1.0618575 ]
  [ 1.8257084 ]
  [-0.54579014]]

 [[ 2.9069736 ]
  [ 1.0850943 ]
  [ 1.9787762 ]
  [ 0.01915958]]

 [[ 2.9069736 ]
  [ 1.0850943 ]
  [ 1.9787762 ]
  [ 0.01915958]]  

是重构错误吗?或者每个整数的概率?如果是这样,为什么它们不在 0-1 的范围内?如果有人能解释这一点,我将不胜感激。

型号:

time_steps = 4
features = 1

train_keys_reshaped = train_integer_encoded.reshape(91, time_steps, features)
test_keys_reshaped = test_integer_encoded.reshape(25, time_steps, features)

model = Sequential()
model.add(LSTM(32, activation='relu', input_shape=(time_steps, features), return_sequences=True))
model.add(LSTM(16, activation='relu', return_sequences=False))
model.add(RepeatVector(time_steps)) # to convert 2D output into expected by decoder 3D
model.add(LSTM(16, activation='relu', return_sequences=True))
model.add(LSTM(32, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(features)))

adam = optimizers.Adam(0.0001)
model.compile(loss='mse', optimizer=adam)

model_history = model.fit(train_keys_reshaped, train_keys_reshaped,
                          epochs=700,
                          validation_split=0.1)

predicted_probs = model.predict(test_keys_reshaped) 

【问题讨论】:

    标签: machine-learning keras lstm autoencoder anomaly-detection


    【解决方案1】:

    正如你所说,它是一个自动编码器。您的自动编码器会尝试重建您的输入。 如您所见,输出值与输入值非常接近,没有大的误差。所以自动编码器训练有素。

    现在,如果您想检测数据中的异常值,您可以计算重构误差(可能是输入和输出之间的均方误差)并设置阈值。

    如果重构误差优于阈值,它将成为异常值,因为自动编码器没有接受过重构异常数据的训练。

    这个架构更好地代表了这个想法:

    我希望这会有所帮助;)

    【讨论】:

    • 谢谢你,确实有帮助:)
    猜你喜欢
    • 1970-01-01
    • 2021-01-07
    • 2022-01-22
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 2021-06-30
    • 2019-10-01
    • 2018-10-01
    相关资源
    最近更新 更多