Predicting Stock Prices using GRU

Hi everyone,

I have attempted the Stock Price Prediction. Please have a look and let me know your feedback.

The general approach is same as in the NYSE Stock Price Prediction Guided Project but with the following variants

  • usage of the holiday package
  • usage of the timeseries generator class from Keras
  • the number of features predicted is same as the total features in the dataset minus the ticker name

Attached is the scrolling screenshot


Thank you
Prakhar Prasad


Hi Prakhar,

Great work. I am intrigued that your predictions are consistently higher than the actual values.
I think it is because you are scaling y.

Also, did you try the LSTM too?
Would you like to build a guided project out of it? I think it will be super useful.

Hi Sandeep,

Thanks. I will try LSTM as well and update here. Yes the prediction is consistently lower than the actual. It did not occur to me that scaling could have an impact. I will try again.
Yes, I will be very glad to build a guided project :slightly_smiling_face:

1 Like

Nice work Prakhar!

How can we scale X but not y? Wont it give huge validation loss? Or have I understood something wrong.

If the model is trained on scaled X_train values, it would do the good prediction on scaled X_train or X_test provided the scaling parameters are same.

A model learns to predict y from X - which can be scaled or not. If you train a model on scaled X value and you are testing on non-scaled, the result will be bad.

If you say scale the value of y, the chances are that the result will be erroneous specifically if the relationship between X and y is non-linear.

Imagine the relationship between X and y is this:

if X < 20: y = X5 - 10
X > 20: y = X
3 - 5

X, y
15, 65
21, 58

Say, we scaled the value, y_scaled = (y - 65)/(65-58)
X, y_scaled
15, 1
21, 0

If you think about, the translated of y_scaled to y would involve multiplying by (65-58) and additing with 65. This would not give great results because y is not linearly dependent on X.

Try doing an experiement with the above example using neural network model.

Thanks @Sandeep. This is quite insightful and well explained.

I tried having X scaled and y as normal and it works fine as you said. But the results are not encouraging . I have used LSTM and I guess I have to fine tune some parameters to get the right results.
I am doing the NN model on Nifty closings for past 14 years.