Help: I tried to predict one predictand with 7 predictors with LSTM but failed
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
Currently I tried to write the code for LSTM so that I can test the accuracy for use 7 predictors to predict 1 predictand. However my result was that
"Error using trainNetwork (line 183)
Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors.:
I tried to look up the solutions but could not find any. Also, I tried to look up the explanation of the Layers and Options but have difficulty to navigate them
https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.lstmlayer.html
https://www.mathworks.com/help/deeplearning/ref/trainingoptions.html
Here is my code:
TengHSPFInputn = csvread('C:\Users\Victor\Documents\PhD\2021 Spring\Teng_HSPF_Input_n.csv')
%Read discharge
Q0=TengHSPFInputn(1:7670,2);
Q1=TengHSPFInputn(1:7670,3);
Q10=TengHSPFInputn(1:7670,4);
Q30=TengHSPFInputn(1:7670,5);
%Read inputs:
input=TengHSPFInputn(1:7670,24:30);
%read total storage
S=TengHSPFInputn(1:7670,31);
%Input the networks
miniBatchSize = 1; %%one predictor sequence
numResponses = 1;
featureDimension = 7670;
num_hidden_units = 100;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(num_hidden_units,'OutputMode','sequence')
fullyConnectedLayer(100) %%50
dropoutLayer(0.1) %%0.5
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ... %%adam
'MaxEpochs',maxepochs, ... %
'GradientThreshold',1, ... %
'InitialLearnRate',0.005, ... %
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
%Train the network with no delay
XTrain = input;
YTrain = Q0;
XTrain = Table2Array(XTrain)
YTrain = Table2Array(YTrain)
net = trainNetwork(XTrain,YTrain,layers,options);
0 comentarios
Respuestas (1)
Shashank Gupta
el 1 de Feb. de 2021
Hi,
You have to convert XTrain and YTrain into cell arrays and the feature dimension which you used as input in InputSequencelayer will be equal to 7 as there are 7 variable attach with each sample. rest of the things seems okay. It should work after this changes. Just to summarize it for your convenience:- the shape of XTrain will be something of the form 7670x1 cell array and each cell array will be of the form 7x1 vector. On the other hand YTrain will be of the form 7670x1 cell array and each cell array will be 1x1 vector. In General, featureDimension is equal to size(XTrain{1},1) and numResponses is equal to size(YTrain{1},1).
I hope this helps.
Cheers
0 comentarios
Ver también
Categorías
Más información sobre Image Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!