简体   繁体   中英

Predicting values in time series for future periods using RNN in Tensorflow

I'm kindly new to deep learning and its approach to time series predicting. Recently I found one article about time series predicting using Recurrent Neural Networks (RNN) in Tensorflow .

In that article the test set is the last 20 values and the model predicts y_pred also for the last 20 values of the dataset and then calculates MSE of y_test and y_pred . My question will be: how can I extend the model to receive the prediction for next periods in the future (actual forecasting)?

Thanks in advance!

In first step you should use real values. Then using predict value to replace last value as you want. Hope the following code could help you.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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