I have been working on a project on the demand for a product. I am using data from 2016 to train the LSTM model. The architecture is as follows:

model_2016 = Sequential()

model_2016.add(LSTM(units = 256, input_shape=(1, look_back), return_sequences = True))

model_2016.add(LSTM(units = 128))

model_2016.add(Dense(units = 1))

trainY = np.reshape(trainY, (len(trainY), ))
valY = np.reshape(valY, (len(valY), ))
opt = Adam(learning_rate=0.0005, decay=1e-6)
model_2016.compile(loss='mean_squared_error', optimizer=opt, metrics=['accuracy'])
hist = model_2016.fit(trainX, trainY, validation_split = 0.2, epochs=100, batch_size=10)

The train_validation img is as follows enter image description here

And the prediction of 2016 data is as follows.

enter image description here

The result of the prediction of 2020 demand is like the result of 2016, it seems like the LSTM model can't get the really precise value. I've checked some articles, like to modify batch size, numbers of neurons, and number of the epoch. But the results don't improve. Do you have any ideas? Appreciate it a lot!!

Updated Section

The following one is the model trained by data from 2016~2019

enter image description here

The train_validation img is as follows

enter image description here

And finally, it's the result of the prediction of demand in 2020

enter image description here

If you have any further suggestions, please tell me.

  • $\begingroup$ Do you have any metrics to evaluate your forecast? How accurate are you expecting it to be? It looks like your LSTM is forecasting dips and peaks one time step too late, am I seeing that right? Also, have you tried using a SARIMA model? $\endgroup$
    – Antonio
    Aug 28, 2021 at 22:31
  • $\begingroup$ ARIMA is a good way I think, but I still don't know how that works. So I choose to use LSTM. I have the metrics to evaluate and use MSE to evaluate the overall loss. In fact, in the image I provided, that did happen. Fortunately, I find some good parameters, then it solves :)) $\endgroup$ Aug 30, 2021 at 4:49

2 Answers 2


It could be due to a lack of data. Your data seems to be over a year, and many data dynamics are seasonal ones. An end of year data would not have the same shape as the rest of the year. Consequently, it would be better to train the data at least over a year (preferably 2 or 3 years to let it learn frequent patterns), and then check the model with a validation data over several months.

If it is already the case, change the dropout value to 0.1, and the batch size to cover a year.

You can also change absolute values to relative ones, because high absolute values may alter the LSTMs predictions quality. Data standardization could also help.

  • $\begingroup$ Thanks for answering:)) Actually, I have trained the model with 4 years of data. But it seems that it doesn't help a lot. The results are presented below ur answers $\endgroup$ Aug 26, 2021 at 8:48
  • $\begingroup$ Understood. Have you tried to lower your dropout to 0.1? (0.2 could be too much) Have you done a batch size over a year? Have you tried 1 layer of LSTM first? $\endgroup$ Aug 26, 2021 at 8:56
  • $\begingroup$ I haven't tried to modify the parameter of the dropout value. That'd be a good choice. About batch_size. I only have tried 1~30. Why 365? I've never done that before. The last question, yes ! I have. But the predictions seemed to be really flat. $\endgroup$ Aug 26, 2021 at 9:07
  • $\begingroup$ 365 to train LSTMs by range of 1 year (and find patterns accordingly). $\endgroup$ Aug 26, 2021 at 9:53
  • $\begingroup$ Thx for the advice. Your suggestions are good. Modifying the dropout value(0.05~0.1) does help. But just a little bit. And different batch size(about 300) seems to do a little bit helps. But overall, the model can't get the precise value. Do you have any other thoughts? $\endgroup$ Aug 26, 2021 at 11:32

I think that the issue is related to a lack of enough data for a neural network problem (LSTM).

You mentioned you added four years, but this still might not be enough. How many data elements do you have for experiment? What is the dispersion between those elements?

My recommendation is to try to approach it with other machine learning algorithms; maybe regression could be a better approach if you have less than 100,000 elements in your dataset.

  • $\begingroup$ Thanks for answering :)) And actually, the demand value I have is just time-series. There are no other variables. Consequently, I choose this model. Furthermore, I have 220k examples $\endgroup$ Aug 28, 2021 at 12:46
  • $\begingroup$ How much is the value for look_back? $\endgroup$ Aug 28, 2021 at 15:48
  • $\begingroup$ I'm still trying it, I have no idea what value is the best. But now, based on what I've tried, the best value is 30. Do you have any recommendations? $\endgroup$ Aug 30, 2021 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.