Error with the function 'trainNetwork'. Error: 'Invalid training data. Responses must be a vector of categorical responses, or a cell array of categorical response sequences.' Line 170.
33 次查看(过去 30 天)
显示 更早的评论
I am attempting to train a NN to classify a Gaussian that has 4 separate classes. I have several different sample sizes, but currently I am focussing on the sample size of 500. The 'Ytrain' vector is called 'labels_train' and when entering it into the function it is 500x1 with each row corresponding to a column in x_train. x_train is a 3x500 vector with 3 features and each column corresponds to the respective row in 'labels_train'. I repeatidly get the error listed above; any idea why? Thanks a bunch.
Also when I attempt to use the categorical() function on the labels_train, I get the following error:
Invalid training data. Sequence responses must have the same sequence length as the corresponding predictors.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/413438/image.png)
5 个评论
Walter Roberson
2020-11-13
The error message is telling you to instead pass in
categorical(labels_train.set3).'
回答(2 个)
Mahesh Taparia
2020-11-18
Hi
I assume the first error is resolved by Walter comment.
It seems the size of 'labels_train' is 1x500 and 'x_train' is 3x500. You are making the transpose of labels while calling trainNetwork which is making labels_train as 500X1 and hence size of input and labels are not consistent. The work around is keep the size of 'x_train' as 500X3 and 'labels_train' as 500X1. Or consider the below code:
net=trainNetwork(x_train.set3',labels_train.set3',layers,options);
Hope it will helps!
2 个评论
jaah navi
2021-6-20
As, I am also getting the same error I am posting here.
I am getting the following error
Error using trainNetwork (line 154)
Invalid training data. Responses must be a vector of categorical responses, or a cell array of categorical response
sequences.
Error in five (line 27)
net = trainNetwork(XTrain,YTrain,layers,options);
In my code, XTrain and YTrain are same which is 3x1 cell. Inside each array both Xtrain and Ytrain has 12x1double, 12x 2double, 12 x3double. Could you provide me any advice for solving it.
Walter Roberson
2021-6-20
That arrangement of class information is not supported. 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
伟
2025-2-12,3:14
I get the same error. I set Xtrain to 'categorical' and Outputmode in latmLayer to 'last'. Then it can be trained.
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!