Stock price predictions of keras multilayer LSTM model converge to a constant value

流过昼夜 提交于 2019-12-01 01:17:10

So, after trying different number of LSTM units and different types of architectures, I realized that the current number of LSTM units causes the model to learns so slowly and 20 epochs were not sufficient for such huge model.For each layer, I changed the number of LSTM units to 64 and also removed Dense(1024)layer and increased the number of epochs from 20 to 400 and results were incredibly close to the ground truth values. I should mention that the dataset used in the new model was different from the former one because I encountered some problems with that dataset . here is the new model:

from keras.optimizers import RMSprop
from keras.initializers import glorot_uniform, glorot_normal, RandomUniform

init = glorot_normal(seed=None)
init1 = RandomUniform(minval=-0.05, maxval=0.05)
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=None, decay=0.0)

model = Sequential()

model.add(LSTM(units=64, dropout=0.2, recurrent_dropout=0.2, 
               input_shape=(x_train.shape[1], x_train.shape[2]), 
               return_sequences=True, kernel_initializer=init))

model.add(LSTM(units=64, dropout=0.2, recurrent_dropout=0.2, 
               return_sequences=False, kernel_initializer=init))


model.add(Dense(1, activation='linear', kernel_initializer= init1))
model.compile(loss='mean_squared_error', optimizer=optimizer )
model.summary()

you can see the predictions here:

It's still not the best model, but at least outperformed the former one. If you have any further recommendation on how to improve it, it'll be greatly appreciated.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!