How do I find slack variables in SVM?/ Distance to the boundary?

조회 수: 11 (최근 30일)
Mech Princess
Mech Princess 2013년 2월 8일
댓글: Aliza Rubenstein 2017년 1월 19일
Hi, I used "svmtrain" to train the algorithm: svmStruct=svmtrain(xdata,group); I used "svmclassify" to classify.
My data is not perfectly linearly separable but I still used a linear classifier. In theory, allowances are made for by a slack variable. (Soft margin) I refer to the toolbox help where the theory is. It mentions the slack variable and 2 ways it is computed. http://www.mathworks.com/help/bioinfo/ug/support-vector-machines-svm.html
My issue is that, svmStruct does not save the slack variable. Neither can I find it in the function to recall it and save it.
If not, how can I find the distance from each data point to the boundary?
Can anyone help me with this? Thanks

답변 (2개)

the cyclist
the cyclist 2013년 2월 8일
It is the input parameter 'boxconstraint' to the svmtrain() command. The default value is 1.
  댓글 수: 5
the cyclist
the cyclist 2013년 2월 8일
Sorry! I thought the slack variable was the parameter C (which is actually the "penalty parameter").
I am not 100% sure that the slack variables have to be explicitly calculated to solve for the support vectors. (It's been a long time since I have used these techniques, and I actually don't have the toolbox at this time, to check.)
Sorry to have been more a distraction than a solution!
Mech Princess
Mech Princess 2013년 2월 9일
Thats fine. Hope someone will answer. Thanks

댓글을 달려면 로그인하십시오.


Ilya
Ilya 2013년 2월 10일
By definition, a slack variable for observation x with label y (-1 or +1) is max(0,1-y*f), where f is the SVM prediction (soft score ranging from -inf to +inf). svmclassify does not return the scores, so you need to compute the SVM scores yourself. Start with the definition of the SVM model, compute kernel products, multiply by the alpha coefficients and add the bias term. It is easier than it sounds.
  댓글 수: 6
Mark
Mark 2014년 8월 19일
Thanks!
Only one remark: I think that this works fine if 'autoscale' is set to false (in the svmtrain function). If the data is scaled, you should also scale Xnew before you feed it to the kernel function:
shift = svm_struct.ScaleData.shift;
scale = svm_struct.ScaleData.scaleFactor;
Now you can scale Xnew:
XnewScaled = ( Xnew - shift ) .* scale;
and then use XnewScale in the kernel function as above:
f = kfun( sv, XnewScaled, kfunargs{:} )' * alphaHat + bias
Aliza Rubenstein
Aliza Rubenstein 2017년 1월 19일
Thanks for this information. I think it should be Xnew + shift, not Xnew - shift. shift is the negative of the mean.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by