Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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);

Respuestas (1)

Nayan
Nayan el 5 de Abr. de 2023
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
Also, if there are further query, it would be easier to help if you could share the ".txt" file used in the above code.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by