我试图用SVC预测奇数和偶数,但是我的输出却不是我期望的
from sklearn import svm
import numpy as np
clf = svm.SVC(kernel='linear')
data = np.array([[0], [1], [2], [3], [4]])
label = np.array([1,0,1,0,1])
clf.fit(data, label)
print(clf.predict([[3]]))
print(clf.predict([[4]]))
print(clf.predict([[5]]))
结果是
[1]
[1]
[1]
我怎么了?我希望[3]和[5]为[0]
我在用:
numpy==1.9.1
scikit-learn==0.16.1
scipy==0.13.3
使用
clf = svm.SVC(kernel='rbf', C=100)
会给预期的
clf.predict(np.arange(10).reshape(-1, 1))
> array([1, 0, 1, 0, 1, 1, 1, 1, 1, 1])
对于该任务,您不能使用此内核来概括训练数据范围之外的内容。我想,您将需要一个正弦曲线的内核(不在sklearn中)来学习此内容。或者,您可以只使用功能的窦道。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句