Matlab libsvm - how to find the w coefficients

ぃ、小莉子 提交于 2019-12-29 17:47:30

问题


How can find what the vector w is, i.e. the perpendicular to the separation plane?


回答1:


This is how I did it here. If I remember correctly, this is based on how the dual form of the SVM optimisation works out.

model = svmtrain(...);
w = (model.sv_coef' * full(model.SVs));

And the bias is (and I don't really remember why its negative):

bias = -model.rho;

Then to do the classification (for a linear SVM), for a N-by-M dataset 'features' with N instances and M features,

predictions = sign(features * w' + bias);

If the kernel is not linear, then this won't give you the right answer.

For more information see How could I generate the primal variable w of linear SVM? , from the manual of libsvm.



来源:https://stackoverflow.com/questions/10131385/matlab-libsvm-how-to-find-the-w-coefficients

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!