Getting this error" Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors."

2 views (last 30 days)
XTrain=xlsread('C:\Users\Subhodip\Desktop\Sumana\Input.xlsx',1,'A1:E1024');
YTrain=xlsread('C:\Users\Subhodip\Desktop\Sumana\Input.xlsx',1,'F1:F1024');
Xtest=xlsread('C:\Users\Subhodip\Desktop\Sumana\Sample1.xlsx',1,'A1:E1024');
Ytest=xlsread('C:\Users\Subhodip\Desktop\Sumana\Sample1.xlsx',1,'F1:F1024');
inputSize=5;
numResponses=1;
numHiddenUnits=100;
layers=[sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
opts=trainingOptions('adam',...
'MaxEpochs',1000,...
'GradientThreshold',0.01,...
'InitialLearnRate',0.0001);
net=trainNetwork(XTrain,YTrain,layers,opts);

Answers (1)

Prasanna
Prasanna on 11 Dec 2024
Edited: Prasanna on 11 Dec 2024
Hi Sumana,
The error message obtained indicates that the sequence length of your predictors('XTrain') and responses('YTrain') do not match. In sequence-to-sequence regression tasks, each input sequence must correspond to an output sequence of the same length. To resolve the error, refer the following steps:
  • Ensure that each sequence in 'XTrain' corresponds to a sequence in 'YTrain' with the same length. If your input data is organized such that each row is a time step and each column is a feature, your response data should also follow this structure.
  • If your data is not already organized into sequences, you may need to reshape it. For example, if each sequence should be 1-dimensional with multiple time steps, you need to reshape your data accordingly.
Check the dimensionality and sequence length in ‘XTrain’ and ‘YTrain’ respectively. Also, ensure the dimensionality of your input and output sequences matches the expectations of your network layers. By ensuring that your input and output sequences are properly aligned and formatted, you should be able to train your LSTM network without encountering the sequence length error. For more information, refer to the following resource:

Categories

Find more on Image 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!