【发布时间】:2018-01-08 01:48:55
【问题描述】:
我有一个 LSTM,它的输出完全一样。我该如何解决这个问题?以下是参数。我很想得到一个一般性的答案,因为这将帮助我了解解决方案,以防我再次看到它。
batch_size = 32
X_train.shape, Y_train.shape, X_test.shape, Y_test.shape
>((1920, 30, 5), (1920, 6), (1696, 30, 5), (1696, 6))
data_dim = X_train.shape[2]
timesteps = X_train.shape[1]
# Expected input batch shape: (batch_size, timesteps, data_dim)
# Note that we have to provide the full batch_input_shape since the network is stateful.
# the sample of index i in batch k is the follow-up for the sample i in batch k-1.
model = Sequential()
model.add(LSTM(32,
return_sequences=True,
stateful=True,
kernel_regularizer=regularizers.l2(0.0001),
batch_input_shape=(batch_size, timesteps, data_dim)))
model.add(Dropout(0.4))
model.add(LSTM(32, return_sequences=True,
kernel_regularizer=regularizers.l2(0.0001),
stateful=True))
model.add(Dropout(0.4))
model.add(LSTM(32, stateful=True))
model.add(Dropout(0.4))
model.add(Dense(6, activation='softmax', use_bias=True))
rms = RMSprop(lr=0.001)
model.compile(loss='categorical_crossentropy',
optimizer=rms,
metrics=['accuracy'])
history = model.fit(X_train, Y_train,
batch_size=batch_size,
epochs=5,
shuffle=False,
validation_data=(X_test, Y_test))
训练后,我得到以下输出:
0b 1b 2b 3b 4b 5b
2017-06-30 0.077203 0.180573 0.314528 0.287455 0.110213 0.030026
2017-07-03 0.077225 0.180570 0.314542 0.287430 0.110204 0.030029
2017-07-04 0.077220 0.180586 0.314541 0.287423 0.110207 0.030023
2017-07-05 0.077193 0.180622 0.314523 0.287426 0.110221 0.030015
2017-07-06 0.077125 0.180695 0.314496 0.287435 0.110257 0.029992
它们都非常相似:(
编辑:忘了提到我使用了 sklearn MinMaxScaler 并将数据缩放到 (-7,7),因为这似乎在过去有效。这是一个正确的方法吗?
【问题讨论】:
-
您选择 -7 和 7 有什么特别的原因吗?也许尝试在 0 和 1 之间缩放。
-
没有什么特别的原因,除了它在以前的数据集上工作过。 0, 1 也产生类似的结果 :(
标签: python machine-learning deep-learning keras data-science