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

Illustration
rameshsingh - 2021-06-14T12:09:03+00:00
Question: Fully connected neural network invalid training data: Responses must be categorical sequences Follow

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?  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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';


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!