- 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
조회 수: 6 (최근 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!