How to resolve the loss function error?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to use this below matlab function.
figure
plot(loss(bag,Xtest,Ytest,'mode','cumulative'))
xlabel('Number of trees')
ylabel('Test classification error')
But this is giving some errors as follows
Error using classreg.learning.internal.classCount
You passed an unknown class '19.746' of type double.
Error in classreg.learning.classif.ClassificationModel/cleanRows (line 271)
C = classreg.learning.internal.classCount(this.ClassSummary.ClassNames,Y);
Error in classreg.learning.classif.ClassificationModel/prepareDataForLoss (line 364)
[X,C,W,Y,rowData] = cleanRows(this,X,Y,W,rowData,obsInRows);
Error in classreg.learning.classif.CompactClassificationEnsemble/loss (line 388)
[X,C,W] = prepareDataForLoss(this,X,Y,W,[],true,true);
Error in Test_RF_Classify (line 25)
plot(loss(bag,Xtest,Ytest,'mode','cumulative'))
I request you to kindly suggest me how to resolve it. I am attaching the code alongwith input file.
I will appreciate your kind help.
Sanchit
댓글 수: 0
답변 (1개)
the cyclist
2023년 7월 25일
편집: the cyclist
2023년 7월 25일
There are a number of potential errors with your code, but I would say that the most fundamental one is that you are using a classification algorithm, but you have a numerical response variable.
Classification algorithms are used to predict categorical or nominal variables (e.g. "Prefers to watch Barbie" vs. "Prefers to watch Oppenheimer").
[The specific MATLAB error arises because the category '19.746' did not appear in the training set, so it cannot appear in the test set.]
You might try to use fitrensemble to fit a regression model instead. Your code will actually run to completion if you do so. But I did not look at your code enough to see if the results would be sensible.
댓글 수: 6
the cyclist
2023년 7월 28일
You should open a new question for that, and accept the answer here if you found it helpful.
참고 항목
카테고리
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!