Troubles in prediction using LSTM
2 views (last 30 days)
Show older comments
I want to make a sequence-to-sequence regression using LSTM.
The training progress showed the convergence of RMSE and Loss to nearly zero.
However, the prediction is very bad, although I use the training data for test.
Whould you recommand what can I do to modify my program?
I do not know what the problem is. (I tried to change 'numHiddenUnits' and number of 'lstmLayer')
I hope your help.
My program is as follow;
%-------------------------------------------------------------------
% The size of Xtrain is 5x1 cell, and the size of each cell is 300x25000.
% The size of Ytrain is 5x1 cell, and the size of each cell is 3x25000.
numResponses = size(Ytrain{1},1); % 3
featureDimension = size(Xtrain{1},1); % 300
numHiddenUnits = 500;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(50)
dropoutLayer(0.5)
fullyConnectedLayer(numResponses)
regressionLayer];
maxEpochs = 60;
miniBatchSize = 20;
options = trainingOptions('adam', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'InitialLearnRate',0.01, ...
'GradientThreshold',1, ...
'Shuffle','never', ...
'Plots','training-progress',...
'Verbose',0);
%-----------Training and Test--------------------
net = trainNetwork(Xtrain,Ytrain,layers,options);
h = predict(net,Xtrain,'MiniBatchSize',1);
1 Comment
Answers (1)
Hong Gi Yeom
on 20 Mar 2019
3 Comments
nahed zemouri
on 20 Jan 2021
if you want normalise your data you can use this function
function dataout = scaledata(datain,minval,maxval)
%
% Program to scale the values of a matrix from a user specified minimum to a user specified maximum
%
% Usage:
% outputData = scaleData(inputData,minVal,maxVal);
%
% Example:
% a = [1 2 3 4 5];
% a_out = scaledata(a,0,1);
%
% Output obtained:
% 0 0.1111 0.2222 0.3333 0.4444
% 0.5556 0.6667 0.7778 0.8889 1.0000
dataout = datain - min(datain(:));
dataout = (dataout/range(dataout(:)))*(maxval-minval);
dataout = dataout + minval;
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!