我确实有以下问题: 我想为二维输入(X_test)预测5个序列,每个序列30天,如下所示。
### This is X_test ###
array([[[0.9889562 , 0.35528348],
[0.98835297, 0.36100796],
[0.98943452, 0.39090311],
[0.97700769, 0.37543382],
[0.96866762, 0.34993568]],
[[0.98835297, 0.36100796],
[0.98943452, 0.39090311],
[0.97700769, 0.37543382],
[0.96866762, 0.34993568],
[0.9680748 , 0.3501392 ]],
[[0.98943452, 0.39090311],
[0.97700769, 0.37543382],
[0.96866762, 0.34993568],
[0.9680748 , 0.3501392 ],
[0.96594827, 0.37902433]],
...,
shape(150,5,2)
我的LSTM模型代码如下(在5个时间步上有2个输入功能,有1个输出):
model = Sequential()
model.add(LSTM(100,activation = "relu", return_sequences = True,input_shape = (5,2)))
model.add(Dropout(0.1))
model.add(LSTM(100,activation = "relu", return_sequences = False))
model.add(Dropout(0.1))
model.add(Dense(1))
model.compile(optimizer="adam", loss="mse")
到目前为止,我只有一维输入,并使用以下代码预测了30天的序列,效果很好:
import numpy
def pred_multi(test_data, start_sequence_day, sequence_length):
predictedsequence = []
test_data1 = test_data[start_sequence_day] #Used X_test as test_data
for i in range(sequence_length):
test_data1 = test_data1.reshape(1,5,2)
prediction = model.predict(test_data1)
predictedsequence.append(prediction)
test_data1 = numpy.insert(test_data1, len(test_data1[0]), prediction)
test_data1 = numpy.delete(test_data1, 0, axis = 0)
return predictedsequence
但是,由于我现在拥有另一个输入功能,因此此代码无法正常工作,因为我仅获得一个输出。但是,下一个时间步需要两个输入作为输入。
有人可以提供帮助吗?我已尝试了所有方法,但不确定如何解决此问题。
非常感谢!