繁体   English   中英

串联预测值LSTM Keras

[英]Concatenate prediction values LSTM Keras

我不知道我是错的还是有道理,但我的想法是使用一个预测,并根据该预测来预测未来值(我在Keras上使用LSTM模型)。 我想做的是:

1)获取前X个已知值(initial_values)

2)使用initial_values进行预测并获取(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))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM