SKLearn SVM:相同数据的不同会员分数

时间:2015-03-28 15:38:39

标签: python scikit-learn svm

我正在训练SVM两次,首先是从文件加载数据,然后在代码中直接分配数据。

这是我的代码

from sklearn import svm
import numpy as np

X = np.genfromtxt("X.txt",delimiter=" ")
Y = np.genfromtxt("Y.txt",delimiter=" ")

fromFile_clf = svm.LinearSVC()
fromFile_clf.fit(X, Y)
fromFile_dec = fromFile_clf.decision_function([[1,2,2]])

U = [[1,1, 0], [1,-1, -1], [-1,1,1], [-1,-1,1]]
V = [0, 1, 2, 3]

direct_clf = svm.LinearSVC()
direct_clf.fit(U, V)
direct_dec = direct_clf.decision_function([[1,2,2]])

print("Loaded From File")
print("X")
print X
print("Y")
print Y
print("Membership")
print fromFile_dec 


print("\n\nData fed directly")
print("U")
print U
print("V")
print V
print("Membership")
print direct_dec 

上述代码的输出是

Loaded From File
X
[[ 1.  1.  0.]
 [ 1. -1. -1.]
 [-1.  1.  1.]
 [-1. -1.  1.]]
Y
[ 0.  1.  2.  3.]
Membership
[[  1.33332130e+00  -2.54545042e+00  -9.27855314e-06  -1.71427699e+00]]

Data fed directly
U
[[1, 1, 0], [1, -1, -1], [-1, 1, 1], [-1, -1, 1]]
V
[0, 1, 2, 3]
Membership
[[  1.33332173e+00  -2.54545295e+00  -1.57102577e-05  -1.71425921e+00]]

两种方法的会员分数似乎不同,第三类的分数也发生了巨大变化。这有什么不对?

0 个答案:

没有答案