簡體   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