Error in using cost matrix for classification model?

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 件のコメント

Stephan
Stephan 2018 年 6 月 23 日
編集済み: Stephan 2018 年 6 月 23 日
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
Sanychen Muk 2018 年 6 月 25 日
Hi Stephan,
I attached the script I'm using, I'm unable to attach the data because of NDA.
Thanks! Sanychen

サインインしてコメントする。

回答 (1 件)

Stephan
Stephan 2018 年 6 月 26 日
編集済み: Stephan 2018 年 6 月 26 日

0 投票

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

カテゴリ

質問済み:

2018 年 6 月 22 日

編集済み:

2018 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by