Could anyone help me how to solve the error stating Y must be a vector of categorical responses or a cell array of categorical response sequences.

37 views (last 30 days)
In my code Y is {3x1} cell
where Y{1,1}=12x1 double
Y{2,1}=12x2 double
Y{3,1}=12x3 double
Could anyone help me how should I change Y to a cell array of categorical response sequences.

Answers (2)

Walter Roberson
Walter Roberson on 20 Jun 2021
Y = cellfun(@categorical, Y, 'uniform', 0)

jaah navi
jaah navi on 20 Jun 2021
With the help of your command I can execute Y(in my code Y is YTrain) but when i tried to implement in my neural network code, error exists as "Error using nnet.internal.cnn.util.NetworkDataValidator/assertValidSequenceResponse (line 349)
Invalid training data. Responses must be a vector of categorical responses, or a cell array of categorical response
sequences" for the following lines.
YTrain = cellfun(@categorical, YTrain, 'uniform', 0)
net = trainNetwork(XTrain,YTrain,layers,options);
Could you please help me to solve it.
  1 Comment
Walter Roberson
Walter Roberson on 20 Jun 2021
Sorry, No, that is not valid training information.
If XTrain is a numeric array, then YTrain must be a categorical vector with number of entries equal to the number of samples in XTrain.
If XTrain is a cell array of numeric arrays, then YTrain must be a cell array, and each entry must be a categorical vector with number of entries each to the number of samples in the corresponding XTrain cell.
YTrain corresponds to class labels: each training sample (no matter how many features it has) corresponds to exactly one class.
Your Y{2,1} is 12 x 2. That would imply that you have two classes for each of 12 samples, or else that you have 12 classes for each of two samples. Either way is not permitted.

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!