6

我在 python 中使用 scikit 包实现 SVM。我在解释plot_separating_hyperplane.py中的“alpha i”值时遇到了困难

import numpy as np
import pylab as pl
from sklearn import svm

# we create 40 separable points
np.random.seed(0)
X = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]
Y = [0] * 20 + [1] * 20

# fit the model
clf = svm.SVC(kernel='linear')
clf.fit(X, Y)
print clf.support_vectors_
#support_vectors_ prints the support vectors
print clf.dual_coef_
#dual_coef_ gives us the "alpha i, y i" value for all support vectors

样本输出

Dual_coef_ = [[ 0.04825885  0.56891844 -0.61717729]]
Support Vectors = 
[[-1.02126202  0.2408932 ]
 [-0.46722079 -0.53064123]
 [ 0.95144703  0.57998206]]

Dual_coef_ 为我们提供了“alpha i * y i”值。我们可以确认“alpha i * y i”的总和 = 0 (0.04825885 + 0.56891844 - 0.61717729 = 0)

我想找出“alpha i”值。这应该很容易,因为我们有“alpha i * y i”值。但我让所有的“阿尔法我”都是负面的。例如,点 (0.95144703, 0.57998206) 位于直线上方(参见链接)。所以 y = +1。如果 y = +1,则 alpha 将为 -0.61717729。同样,点 (-1.02126202, 0.2408932) 位于该线下方。所以 y = -1,因此 alpha = -0.04825885。

为什么我的 alpha 值为负数? 我的解释错了吗?任何帮助将不胜感激。


供你参考,

对于支持向量分类器 (SVC),

给定训练向量 , i=1,..., n, 在两个类别中,以及一个向量使得 ,SVC 解决了以下原始问题:

在此处输入图像描述

它的对偶是

在此处输入图像描述

其中'e'是全1的向量,C > 0是上界,Q是n乘n半正定矩阵,在此处输入图像描述在此处输入图像描述核。在这里,训练向量被函数映射到更高的(可能是无限的)维空间。

4

1 回答 1

4

我认为您只是错误地解释了 y 。我猜在线上方是 y=-1 和下方 y=+1。

为什么你认为它是相反的?

对于一个二级问题,我认为是“第一类”。即编号最小的一个是+1,另一个是-1。这是一个 LibSVM 约定。

于 2012-10-06T10:56:13.773 回答