Invalid training data. Predictors must be a N-by-1 cell array of sequences, where N is the number of sequences. All sequences must have the same feature dimension and at least
2 次查看(过去 30 天)
显示 更早的评论
i am unable to resolve this error
clc;
close all;
clear all;
% Load dataset
load 's0486.txt'
% Open text file
fid = fopen('s0486.txt','r');
% Read text file into cell array
C = textread('s0486.txt','%s','delimiter','\n');
% Close text file
fclose(fid);
X= C(1,:);
% mydata contains a signal dataset with input features X and labels Y
%labels
Y1= cell(1,15);
Y1(1:6)={ 'normal'};
Y1(7:15)={'lvh'};
Y=categorical (Y1);
% Split dataset into training and testing sets
trainInd= [1:12];
testInd= [13:15];
XTrain = C(trainInd,:);
YTrain = Y(trainInd);
XTest = C(testInd,:);
YTest = Y(testInd);
% Define RNN architecture
inputSize = size(XTrain,1);
numHiddenUnits = 100;
outputSize = 2;
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(outputSize)
softmaxLayer
classificationLayer];
% Set training options
options = trainingOptions('adam', ...
'MaxEpochs',50, ...
'MiniBatchSize',64, ...
'SequenceLength','longest', ...
'Shuffle','every-epoch', ...
'Verbose',false, ...
'Plots','training-progress');
% Train RNN
[net, traininfo]= trainNetwork(XTrain,YTrain,layers,options);
% Test RNN
YPred = classify(net,XTest);
accuracy = sum(YPred == YTest)/numel(YTest);
fprintf('Test accuracy: %f\n',accuracy);
0 个评论
回答(1 个)
Nayan
2023-4-5
Hi,
I reproduced the exact error with a test .txt file. The code is failing at the line
It seems the error has occured because the "responses/YTrain(in your case)" argument of the "trainNetwork" should be a N*1 vector. However in your code it is 1*N vector.
I would refer you to the look at "Train Network for Sequence Classification" example in
Train deep learning neural network - MATLAB trainNetwork (mathworks.com) for more intution.
Also, if there are further query, it would be easier to help if you could share the ".txt" file used in the above code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!