# LSTM model, poor performance

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))

trainY = np.reshape(trainY, (len(trainY), ))
valY = np.reshape(valY, (len(valY), ))
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

And the prediction of 2016 data is as follows.

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

The train_validation img is as follows

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

If you have any further suggestions, please tell me.

• 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? Aug 28 at 22:31
• 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 :)) Aug 30 at 4:49

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.

• 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 Aug 26 at 8:48
• 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? Aug 26 at 8:56
• 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. Aug 26 at 9:07
• 365 to train LSTMs by range of 1 year (and find patterns accordingly). Aug 26 at 9:53
• 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? Aug 26 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.

• 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 Aug 28 at 12:46
• How much is the value for look_back? Aug 28 at 15:48
• 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? Aug 30 at 1:15