【问题标题】:LSTM Sequence to sequence anomaly detectionLSTM 序列到序列异常检测
【发布时间】:2019-06-19 15:13:23
【问题描述】:

我有一个简单的数据框,想构建我的 LSTM 架构,以便进行异常检测

from numpy import array
from keras.models import Sequential, Model
from keras.layers import Input, Dense, LSTM, RepeatVector,TimeDistributed
from keras import optimizers
from keras.callbacks import EarlyStopping

X = array([0.1, 0.2, 0.3, 0.4, 25, 0.5, 0.6, 0.7]) 
X_train = X.reshape(1, 8, 1)
y = X.reshape(1, 8)

我希望我的 LSTM 编码器在尝试学习序列时告诉我数据点 25 处的异常情况

model = Sequential()
model.add(LSTM(4, input_shape=(8, 1), return_sequences=True))
model.add(TimeDistributed(Dense(1)))

model.compile(loss='mean_squared_error', optimizer='adam')
print(model.summary())

history = model.fit(X_train, y, epochs=500, batch_size=1, verbose=2)
result = model.predict(X_train, batch_size=1, verbose=0)

结果是

[0.6, 0.9, 1.0, 1.1, 2.4, 1.1, 1.3, 1.2]

在数据点 25 对我来说这看起来不像异常

我应该对我的架构进行哪些更改,以使其清晰可见

【问题讨论】:

    标签: python deep-learning lstm anomaly-detection


    【解决方案1】:

    我不确定您为什么没有收到标签形状的错误。

    不管怎样,增加单位就可以解决问题。

    y = X.reshape(1, 8, 1)

    model.add(LSTM(100, input_shape=(8, 1), return_sequences=True))

    print(result)

    [[[ 0.3147867 ] [ 0.40975055] [ 0.19347075] [ 0.43266642] [24.969408 ] [ 0.5055496 ] [ 0.61411744] [ 0.72490424]]]

    但是,这只是一个训练示例。我建议使用带有训练和验证集的更大数据集并检查验证损失。

    【讨论】:

      猜你喜欢
      • 2015-07-23
      • 2019-10-13
      • 2021-02-19
      • 1970-01-01
      • 2016-10-20
      • 2023-03-07
      • 2021-01-07
      • 2018-09-22
      • 2021-04-21
      相关资源
      最近更新 更多