Defining cost function in partitioned SVM model

1 次查看(过去 30 天)
Hello,
I'm trying to train an SVM using leave one out cross validation with a cost function that takes into account the prior probabilities for each class. The version I'm working with is R2014a.
First, I set up a partitioning scheme as follows:
c = cvpartition(outcomeVar,'LeaveOut');
Then, I set up a cost function:
costFcn = [0 1; 1.4545 0];
Then I define the model.
mdl = fitcsvm(predictorDat,outcomeVar,'CVPartition',c,'KernelFunction','Polynomial','PolynomialOrder',3,'KernelScale',KS, ...
'BoxConstraint',BC,'KKTTolerance',.001,'Cost',costFcn,'ClassNames',CNames)
Now, when I look at the model parameters I find that the cost function is not the one that I defined.
mdl.Cost
ans =
0 1
1 0
Furthermore, if I look at one of the partitions I see the same.
mdl.Trained{1}.Cost
ans =
0 1
1 0
When I look at the priors of the model, they seem to be adjusted according to the cost function I initially defined.
So, my question is: does Matlab update the the priors and reset the cost function to the default as an equivalent operation to leaving the cost function as I define it and setting the priors to be equivalent to the observed class frequencies?
Furthermore, is there a reason why the kfoldLoss returned in individual mode is ordered according to the partitioning scheme, whereas the kfoldMargin is returned according to the order of the input data?

回答(1 个)

Ilya
Ilya 2015-7-28
So, my question is: does Matlab update the the priors and reset the cost function to the default as an equivalent operation to leaving the cost function as I define it and setting the priors to be equivalent to the observed class frequencies?
Yes.
Furthermore, is there a reason why the kfoldLoss returned in individual mode is ordered according to the partitioning scheme, whereas the kfoldMargin is returned according to the order of the input data?
Loss is defined per dataset; there is one loss value for each cross-validation fold. Margin is defined for each observation; there are always as many margins as there are observations. Loss values are always ordered by folds, and margins are always ordered by observations.
  2 个评论
Kevin Guise
Kevin Guise 2015-7-28
编辑:Kevin Guise 2015-7-28
Thanks, this makes perfect sense. I've noticed that kfoldEdge is not ordered the same as kfoldMargin, though the former depends on the latter. Are you aware of the rationale behind this? Might it have to do with dependence on individual folds?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by