gpt4 book ai didi

python - 在 Tensorflow 中使用 RNN 预测 future 时间序列中的值

转载 作者:太空宇宙 更新时间:2023-11-03 14:37:37 25 4
gpt4 key购买 nike

我找到一篇关于 time series predicting using Recurrent Neural Networks (RNN) in Tensorflow 的文章.

在那篇文章中,测试集是最后 20 个值,模型也针对数据集的最后 20 个值预测 y_pred,然后计算 y_testy_pred

如何扩展模型以接收 future 下一时期的预测(实际预测)?

最佳答案

第一步,您应该使用实际值。然后根据需要使用预测值替换最后一个值。希望以下代码可以帮助您。

with tf.Session() as sess:
saver.restore(sess, './model_saved')
preds = []
X_batch = last_n_steps_value
X_batch = X_batch.reshape(-1, n_steps, 1)
for i in range(number_you_want_to_predict):
pred = sess.run(outputs, feed_dict={X: X_batch})
preds.append(pred.reshape(7)[-1])
X_batch = X_batch[:, 1:]
# Using predict value to replace real value
X_batch = np.append(X_batch, pred[:, -1])
X_batch = X_batch.reshape(-1, n_steps, 1)

关于python - 在 Tensorflow 中使用 RNN 预测 future 时间序列中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46810120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com