Cost in fitcecoc input

3 vues (au cours des 30 derniers jours)
Elena Casiraghi
Elena Casiraghi le 24 Août 2019
Commenté : Elena Casiraghi le 30 Août 2019
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

Réponse acceptée

Shashank Gupta
Shashank Gupta le 29 Août 2019
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 commentaires
Shashank Gupta
Shashank Gupta le 30 Août 2019
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 le 30 Août 2019
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!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by