Error in using cost matrix for classification model?
Mostrar comentarios más antiguos
I've been running into an error when setting up my cost matrix,
Error using classreg.learning.classif.FullClassificationModel.processCost (line 302) Missing misclassification cost for class 1.
I set it up using
cost.ClassificationCosts = [ 0 1; 10 0];
cost.ClassNames = classNames;
Am I missing something in the way I set up my cost matrix?
Thanks
2 comentarios
Hi,
please provide your code or attach the m-file. If possible attach data.
Without these informations it is hard to help. One possible reason could be, that the order of class names can change the order of classes, which could mean that your cost matrix has to be rewritten.
Best regards
Stephan
Sanychen Muk
el 25 de Jun. de 2018
Respuestas (1)
Hello,
I suspect the following problem - but I can not test it without data ...
You create a struct called "cost" that contains the cost matrix and the names of the classes in each field. When you make the call:
costAdaBoostModel = fitcensemble (trainData, rainLabels, 'Method', 'AdaBoostM1',...
'NumLearningCycles', 200, 'Learners', treeTemplate, 'LearnRate', 1, 'Cost', cost);
with:
... 'Cost', cost);
you call a struct and not the cost matrix itself. You can try it in the editor:
>> cost
cost =
struct with fields:
ClassificationCosts: [2×2 double]
ClassNames: {'Non-Thermostable' 'Thermostable'}
I assume you should call it that way:
... 'Cost', cost.ClassificationCosts);
what - when you execute it in the editor shows the cost matrix:
>> cost.ClassificationCosts
ans =
0 1
10 0
Since I can only assume that without data, I can only recommend that you try this approach and come back with a result.
Best regards
Stephan
Categorías
Más información sobre Classification Ensembles en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!