MATLAB Answers

Cost in fitcecoc input

13 ビュー (過去 30 日間)
Elena Casiraghi
Elena Casiraghi 2019 年 8 月 24 日
コメント済み: Elena Casiraghi 2019 年 8 月 30 日
Dear,
I'm trying to train an ecoc model using svm as base classifiers.
Since the data in X is unbalanced, I would like to use cost-sensitive svms, that is, I would like to use the misclassification cost matrix, where where cost(i,j) is the cost of misclassifying i into class j.
Using svms I could then use the following code:
numLabels = 5; % suppose I have 5 classes
cost = zeros(numLabels,numLabels);
for nL1 = 1: numLabels; for nL2 = 1: numLabels
if nL1 == nL2; cost(nL1,nL1)=0;
else; cost(nL1,nL2)= double(sum(uint8(labelsRed==nL1)))/double(sum(uint8(labelsRed==nL2))); end
end; end
X = randi(1000, 21); % my data has 1000 training points, each having 21 features
labels = randi(5,1000,1);
mdl = fitcsvm(X, labels, 'Cost', cost,'Standardize',true,'Leaveout','on','KernelFunction','rbf','OptimizeHyperparameter', 'auto');
% if I wanted to create the cecoc I'm doing
t = templateSVM('Standardize',true,'KernelFunction','rbf');
mdlsvmCecoc = fitcecoc(X,labels, ...
'Leaveout','on', 'Cost', cost, ...
'OptimizeHyperparameter', 'auto',...
'coding', 'ternarycomplete','Learners',t);
is it right?
Is the cost used here to weight the 5 classes in different ways?
I'm asking since cecoc produces many binary problems by somehow splitting the classes.
How is the cost used here?
THANKS

  0 件のコメント

サインイン to comment.

採用された回答

Shashank Gupta
Shashank Gupta 2019 年 8 月 29 日
I am not sure what LabelsRed variable is in your code but let’s just assume you have defined misclassification cost matrix correctly.
MATLAB function “fitcecoc” trains or cross-validate an SVM only, Since SVM are binary learner models only and therefore this function treats multiple classes as a combined binary SVM model. By default, it uses a one-versus-one coding design, you can understand the model design by accessing the “mdlsvmCecoc” object, you can also look at each of the binary learner by accessing “BinaryLearner” property of the object. So probably that’s the reason of getting binary problems.
I hope it helps!

  3 件のコメント

Elena Casiraghi
Elena Casiraghi 2019 年 8 月 29 日
Dear Shashank, thanks a lot!
I knew what you wrote.
The ecoc classifiers split the dataset (which contains N classes) in order to create several binary problems.
However, the cost matrix is NxN where N is the number of classes.
Therefore, how is the cost used by ecoc?
Do you happen to know?
Shashank Gupta
Shashank Gupta 2019 年 8 月 30 日
Hi Elena,
I kind of understand what you are trying to say, sorry if I misinterpreted you question earlier.
Let’s say the “ecoc” first solving a binary problem between 1st and 3rd class, then SVM optimizer choose the corresponding submatrix defined in cost matrix (which is cost([1,3],[1,3]) in our case), like this for every binary problem, “ecoc” can always find a corresponding cost submatrix to optimize with.
I hope this make more sense.
Elena Casiraghi
Elena Casiraghi 2019 年 8 月 30 日
Thanks! I didn't Think it was like that because I know ecoc can mix classes when building the binary classifiers. But anyway, this solves the problem!!!

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。


Translated by