简体   繁体   中英

Matlab libsvm - how to find the w coefficients

如何找到向量w,即垂直于分离平面的方向?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM