Fully connected neural network invalid training data: Responses must be categorical sequences

Hello
I am trying to create a Fully Connected Neural Network to classify feature data. I have input data as a 4000x2 cell containing in column 1 the input features as 12x5 double (12 features with 5 values for each), and in column 2 the response lables (0 or 1). Before I input data to the network I arrange column 1 and 2 in seperate variables as a x = 4000x1 cell (with features) and y = 4000x1 categorical (with responses). However, when I run trainNetwork I get the following error message:
Error using trainNetwork (line 165)
Invalid training data. If the network outputs sequences, then the responses must be a cell array of categorical sequences, or
a categorical sequence.
I arrange and convert resonses from the input cell (4000x2) to a categorical by using categorical :
yTemp = inputDataCell(1:4000,2);
y = categorical(cell2mat(yTemp));
Question: How is my cell array of categorical responses not a categorical sequence and how do I make it so?

 Accepted Answer

I found my own answer.
My fault was that I did in fact not give the network the responses as a sequence, as I thought. (surprise)
The network recieved input training data as a 4000x1 cell of 12x5 matrices and responses as a 4000x1 cell of 1x1 categorical lables (0 or 1). As the input has dimension 12 for each of the features and a sequence of 5, the response must also have a sequence of 5, hence the response 4000x1 cell should contain 1x5 categorical.
I fixed the response with a for loop adding the value of the response to a matrix from column 1 to 5:
yTemp = inputDataCell(1:4000,2);
yCategory = categorical(cell2mat(yTemp));
for i = 1:length(yCategory)
tempClassNum = yCategory(i,1);
tempClassMatrix(1,1:5) = tempClassNum;
yCC(i) = {tempClassMatrix(:,:)};
end
ySequence = yCC';

3 Comments

I am still having an issue with my code. Can you check the thread that i posted?
I encountered the same problem, although this solution did not resolve the error as it would still show "Invalid training data. Responses must be a cell array of categorical response sequences." May I see your network structure? As my training data works on sequence to label networks, but not on my CNN.
But this doesn't make any sense. If we consider this: https://www.mathworks.com/matlabcentral/answers/860840-could-anyone-help-me-how-to-solve-the-error-stating-y-must-be-a-vector-of-categorical-responses-or-a#comment_1594535 then the responses vector must be the same length as the number of cells of the input cell array.
As Walter said: "YTrain corresponds to class labels: each training sample (no matter how many features it has) corresponds to exactly one class."

Sign in to comment.

More Answers (0)

Categories

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

Products

Release

R2019a

Asked:

on 7 Apr 2019

Commented:

on 18 Sep 2023

Community Treasure Hunt

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

Start Hunting!