简体   繁体   English

Matlab libsvm-如何找到w系数

[英]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. 如果我没记错的话,这是基于SVM优化的双重形式的工作原理。

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, 然后针对具有N个实例和M个特征的N个M个数据集“特征”进行分类(对于线性SVM),

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? 有关更多信息,请参见如何生成线性SVM的原始变量w? , from the manual of libsvm. ,来自libsvm的手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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