在Tensorflow中使用RNN预测未来时间段的时间序列值

问题描述:

我对于深度学习及其对时间序列预测的方法颇为陌生。最近我发现了一篇关于time series predicting using Recurrent Neural Networks (RNN) in Tensorflow的文章。在Tensorflow中使用RNN预测未来时间段的时间序列值

在这篇文章中,测试仪在过去的20个值和模型预测y_pred也为数据集的最后20个值,然后计算y_testy_pred MSE。我的问题是:如何扩展模型以接收未来下一阶段的预测(实际预测)?

在此先感谢!

+0

问题在于,谁在时间序列预测中编写神经网络,对数据集中的输入数据进行预测。但是如何对未来时期(不存在)进行预测? – HalfPintBoy

第一步你应该使用真实值。然后使用预测值来替换上一个值。 希望以下代码可以帮助你。

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)