Tuesday, 24 July 2018

How to forecast using the Tensorflow model?

I have created tensorflow program in order to for the close prices of the forex. I have successfully created the predcitions but failed understand the way to forecast the values for the future. See the following is my prediction function:

test_pred_list = []

def testAndforecast(xTest1,yTest1):
#     test_pred_list = 0
    truncated_backprop_length = 3
    with tf.Session() as sess:
    #     train_writer = tf.summary.FileWriter('logs', sess.graph)
        tf.global_variables_initializer().run()
        counter = 0
#         saver.restore(sess, "models\\model2298.ckpt")
        try:
            with open ("Checkpointcounter.txt","r") as file:
                value = file.read()
        except FileNotFoundError:
            print("First Time Running Training!....")  
        if(tf.train.checkpoint_exists("models\\model"+value+".ckpt")):
            saver.restore(sess, "models\\model"+value+".ckpt")
            print("models\\model"+value+".ckpt Session Loaded for Testing")
        for test_idx in range(len(xTest1) - truncated_backprop_length):

            testBatchX = xTest1[test_idx:test_idx+truncated_backprop_length,:].reshape((1,truncated_backprop_length,num_features))        
            testBatchY = yTest1[test_idx:test_idx+truncated_backprop_length].reshape((1,truncated_backprop_length,1))


            #_current_state = np.zeros((batch_size,state_size))
            feed = {batchX_placeholder : testBatchX,
                batchY_placeholder : testBatchY}

            #Test_pred contains 'window_size' predictions, we want the last one
            _last_state,_last_label,test_pred = sess.run([last_state,last_label,prediction],feed_dict=feed)
            test_pred_list.append(test_pred[-1][-1]) #The last one

Here is the complete jupyter and datasets for test and train:
My repository with code.

Kindly, help me how I can forecast the close values for the future. Please do not share something related to predictions as I have tried. Kindly, let me know something that will forecast without any support just on the basis of training what I have given.

I hope to hear soon.



from How to forecast using the Tensorflow model?

No comments:

Post a Comment