Why LSTM training is not done properly?

3 views (last 30 days)
Hi everyone!
I'm trying to train LSTM with 17521 data points. But with this amount of data, network training is not done properly. When I reduce the data to 8785(data for one year), the training is done to the end. But by increasing the data to 17521(data for two years), I receive NaN value in the YPred variable. This is my code:
YTrain = cell2mat(A_orig(2:17521,end))';
XTrain = cell2mat(A_orig(2:17521,3:end-1))';
XTrain = num2cell(XTrain,1);
YTrain = num2cell(YTrain,1);
%%Define Network Architecture
numResponses = size(YTrain{1},1);
featureDimension = size(XTrain{1},1);
numHiddenUnits = 500;
layers = [ ...
fullyConnectedLayer(500) %%50
dropoutLayer(0.1) %%0.5
maxepochs = 500;
options = trainingOptions('adam', ... %%adam
'MaxEpochs',maxepochs, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
%%Train the Network
net = trainNetwork(XTrain,YTrain,layers,options);
%%Test the Network
YTest = cell2mat(A_orig(17546:26305,end))';
XTest = cell2mat(A_orig(17546:26305,3:end-1))';
XTest = num2cell(XTest,1);
YTest = num2cell(YTest,1);
net = resetState(net);
YPred = predict(net,XTest);
y1 = (cell2mat(YPred(1:end, 1:end))); %have to transpose as plot plots columns
y2 = (cell2mat(YTest(1:end, 1:end))');
When Number of data is 8785, the output for training is:
Please help me.Thanks alot.

Answers (1)

the cyclist
the cyclist on 5 Sep 2021
I doubt that it is actually the size of the data that is the problem.
You could test that idea by running the second year (which is about the same size dataset as the one that runs) by itself. Perhaps the problem is something in the 2nd-year data, and not the size.
It's difficult to diagnose the problem without seeing the data. Can you upload the data in a MAT file?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!