Python Scikit学习SVC决策函数

Python Scikit学习SVC决策函数,python,Python,我正在用svm.svc对Iris数据集进行分类,并试图理解方法决策函数。我将以下代码的结果与方法决策函数的结果进行了比较。但当我使用“ovr”时,它们是不同的 有人能告诉我,当使用“ovr”时,方法决策函数是如何工作的吗 vec = test_x[0,:].reshape(1,-1) sv = model.support_vectors_ nv = model.n_support_ a = model.dual_coef_ k = [np.dot(vi, vec.transpose()) fo

我正在用svm.svc对Iris数据集进行分类,并试图理解方法决策函数。我将以下代码的结果与方法决策函数的结果进行了比较。但当我使用“ovr”时,它们是不同的

有人能告诉我,当使用“ovr”时,方法决策函数是如何工作的吗

vec = test_x[0,:].reshape(1,-1)
sv = model.support_vectors_
nv = model.n_support_
a  = model.dual_coef_
k = [np.dot(vi, vec.transpose()) for vi in sv]
b = model.intercept_
coef = model.coef_

start = [sum(nv[:i]) for i in range(len(nv))]
end = [start[i] + nv[i] for i in range(len(nv))]

c = [sum(a[ i ][p] * k[p] for p in range(start[j], end[j])) + \
     sum(a[j-1][p] * k[p] for p in range(start[i], end[i]))\
      for i in range(len(nv)) for j in range(i+1,len(nv))]
print(c)
print(coef.dot(vec.transpose())) # This two results are the same

cs = [sum(x) for x in zip(c, b)]
print(cs)
print(coef.dot(vec.transpose()) + b.reshape(-1,1)) # This two results are the same

print(model.decision_function(vec)) # This result differs from cs using "ovr"