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

回答(1 个)

the cyclist
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 个评论
Sanchit
Sanchit 2023-7-28
编辑:Sanchit 2023-7-28
Thank you very much for your kind help. In an another problem, I want to compute the daily mean of 8 variables over Lat x Lon x Time. My netcdf file contains these 8 variables for 03,06,09 and 12 GMT observations over 9 years data. I am attaching the matlab code with input file. I request to please have a look on code and suggest me how to fix it.
I would be grateful to you for your kind help.
Sanchit
the cyclist
the cyclist 2023-7-28
You should open a new question for that, and accept the answer here if you found it helpful.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by