Matlab libsvm-如何找到w系数 [英] Matlab libsvm - how to find the w coefficients
问题描述
如何找到向量w,即与分离平面垂直的向量?
How can find what the vector w is, i.e. the perpendicular to the separation plane?
推荐答案
这就是我的操作方式对偶格式.
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;
然后对具有N个实例和M个特征的N个M个数据集特征"进行分类(对于线性SVM)
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.
有关更多信息,请参见如何生成线性SVM的原始变量w? ,来自libsvm的手册.
For more information see How could I generate the primal variable w of linear SVM? , from the manual of libsvm.
这篇关于Matlab libsvm-如何找到w系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!