- First column: a cell array where each cell contains a 1×m numeric row vector (the features)
- Second column: a categorical array representing the labels
Error received when applying example code for trainNetwork with numerical features to 2 d feature data, with integer classification codes
1 次查看(过去 30 天)
显示 更早的评论
I receieved the following error when running the example code for trainNetwork with numerical features on 2d numerical feature data with integer classification codes.
Error using trainNetwork
Invalid training data table for classification. Predictors must be in the first column of the table, as a cell array of image paths orimages. Responses must be after the first column, as categorical labels.
Error in DLNetwork2 (line 143)
[net,info] = trainNetwork(tblTrain,layers,options);
Error in TestReluCVM (line 213)
[net,info,Ypred,Ytest] = DLNetwork2(X',Y);
NOTE: The data was not image data. X was (n,2) numeric data; Y was (n,1) integer classification codes.
I don't understand how to fix the error.
Thank you.
Linda Ness
0 个评论
回答(1 个)
TARUN
2025-6-12
The error you're encountering arises because trainNetwork expects the input table for classification with numeric features to follow a specific structure:
To fix your issue, you can convert the numeric feature matrix X into a cell array using num2cell(X,2) and convert the label vector Y into a categorical array. Then construct the table like this:
predictorCell = num2cell(X, 2);
Ycategorical = categorical(Y);
tbl = table(predictorCell, Ycategorical, 'VariableNames', {'Predictors','Response'});
Make sure to use this tbl for both training and testing data splits, and remove any one-hot encoding or splitvars logic that’s not needed here.
You can refer to the official MATLAB documentation to learn more about
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!