我有一個長度爲1000的數字序列,我把它分成100個長度的序列。所以我最終得到901個長度爲100的序列。讓第一個900爲trainX
。 trainY
是這些序列的第2到901個。一對一LSTM
在keras中,我希望構建以下圖片模型:重要的功能是$ X_1 $映射到$ X_2 $,$ X_2 $映射到$ X_3 $等等。忽略我沒有繪製100個單位的事實。
在keras中,我知道如何構建$ X_1 $到$ X_ {100} $映射到$ X_ {101} $(多對一)的模型。這是由以下完成:
batch_size = 1
time_steps = 100
model = Sequential()
model.add(LSTM(32, batch_input_shape=(batch_size, time_steps, 1), stateful=True))
model.add(Dense(1))
但是,在多對多的情況下,以下夾頭的錯誤:
model = Sequential()
model.add(LSTM(32, batch_input_shape=(batch_size, time_steps, 1), stateful=True, return_sequences=True))
model.add(Dense(1))
我試着說return_sequences=True
保持一個事實,即100個輸出給。我得到錯誤Input 0 is incompatible with layer dense_6: expected ndim=2, found ndim=3
,我想這是可以理解的,因爲Dense
只能預測batch_size x hidden_nodes
尺寸矩陣作爲輸入,而在我的情況下,它輸出batch_size x time_steps x hidden_nodes
。
所以我的問題是如何得到一個LSTM的行爲如圖所示。在密集層中,我不會無意中引用當前時間步的前面(或後面)的隱藏層。
注意:我沒有執行代碼。我只是寫了它。 – Nejla
就這樣你知道我已經知道如何做這個版本的預測。我想要的模型與你所提到的稍有不同。 「在keras中,我知道如何建立$ X_1 $到$ X_ {100} $映射到$ X_ {101} $(多對一)的模型」 –