1

I have built an LSTM model that can forecast the future prices. I have tested the same with ground truth value that exists already to know the accuracy of the model. Now I wanted to use the same model to predict the value for which we dont know the ground truth.I did the below code to perform forecasting for 449 new records.

Test = Stock_AREIT[len(Stock_AREIT)-60:]
Test=Test['1. open']
inputs=Test.values
inputs = inputs.reshape(-1,1)

# Scale inputs but not actual test values
inputs = sc.transform(inputs)
for test in range(0,449):
inputs=np.append(inputs,predicted_stock_price)
inputs=inputs.reshape(-1,1)
print(inputs.shape)
X_test=[]
for i in range(60, 61):
    X_test.append(inputs[test:i+test,0])
# make list to array
X_test = np.array(X_test)
X_test = np.reshape(X_test,(X_test.shape[0], X_test.shape[1],1))
predicted_stock_price = regressor.predict(X_test)
inputs=np.delete(inputs,len(inputs)-1,axis=0)
inputs=np.append(inputs,predicted_stock_price)
inputs=inputs.reshape(-1,1)
print("currently running {}".format(test))

The actual forecast of the model should be like the below figure enter image description here

But for the code above, I am getting the below graph enter image description here

Can you please let me know where I am going wrong ? Please let me know if you need further details

SrihariRaghu
  • 123
  • 2
  • 11
  • I think I figured out. The actual graph (figure 1) actually uses the proper ground truth which makes it more accurate in prediction. Whereas my result actually using predicted values in its time step. I think my understanding is correct. But let me know your inputs as well – SrihariRaghu Jun 20 '18 at 07:32

1 Answers1

0

You haven't transformed back the values. The predicted value is based on transform data.

This should work:

predicted_stock_price_orig = inputs.inverse_transform(predicted_stock_price)

Please refer to this question for more help: scikit-learn: how to scale back the 'y' predicted result

Alireza HI
  • 1,873
  • 1
  • 12
  • 20