【发布时间】: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