Clear Filters
Clear Filters

How to resolve the loss function error?

4 views (last 30 days)
Sanchit
Sanchit on 25 Jul 2023
Commented: the cyclist on 28 Jul 2023
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

Answers (1)

the cyclist
the cyclist on 25 Jul 2023
Edited: the cyclist on 25 Jul 2023
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 Comments
Sanchit
Sanchit on 28 Jul 2023
Edited: Sanchit on 28 Jul 2023
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 on 28 Jul 2023
You should open a new question for that, and accept the answer here if you found it helpful.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!