串联预测值lstm keras



我不知道我是否错了或是否有意义,但是,我的想法是使用单个预测,并基于该预测(我使用KERAS上的LSTM模型)。我要做的是:

1)获取第一个已知值(initial_values)

2)使用initial_values和get(initial_prediction)预测。

3)删除initial_values的第一个元素,并附加initial_prediction

4)从步骤2)重复x次。

我的代码看起来像这样:

predictions = []
y_test_concat = []
num_steps_before = 30
# Step 1
# X_test_scaled_shape: (192, 1)
y_test_concat.append(X_test_scaled[:num_steps_before,:]) 
y_test_concat = np.array(y_test_concat)
y_test_concat.reshape(y_test_concat.shape[0],y_test_concat.shape[1],1)
# Step 2
simulated_predictions.append(model.predict(y_test_concat))
# Step 3 (where I get stucked)
num_steps_to_predict = 10
for i in range(1,num_steps_to_predict):
  ...

因此,在下一次迭代中,阵列应该喜欢:

[initial_value2,initial_value3,...initial_value30, initial_prediction]
[initial_value3,initial_value4,...initial_prediction, initial_prediction2]
...
[initial_value20,initial_value21,...initial_predictionX, initial_predictionY]

有什么想法吗?我想知道Keras中是否已经实现了使用LSTM进行此类操作的事情。

感谢@lukedeluccia的回答,我提出了解决方案:

num_steps_before = 30
initial_values = np.array([X_test_scaled[:num_steps_before,:]])
predictions = initial_values
for i in range(0,num_steps_before):
  prediction = model.predict(predictions)
  predictions = np.append(predictions,[prediction])
  predictions = np.delete(predictions,0)
  predictions = predictions.reshape((1,predictions.shape[0],1))

最新更新