关于python sklearn 中SVM分类的问题
我的环境是python3.6.3我的代码:fromsklearnimportsvmX=[[0,0],[1,1],[1,0]]y=[0,1,1]clf=svm.SVC()#...
我的环境是python 3.6.3
我的代码:
from sklearn import svm
X = [[0, 0], [1, 1], [1, 0]]
y = [0, 1, 1]
clf = svm.SVC() # class
clf.fit(X, y)
result = clf.predict([2, 2])
print(result) # target
报错:
ValueError: Expected 2D array, got 1D array instead:array=[ 2. 2.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
请问:1.到底啥问题? 2.怎么写才对? 展开
我的代码:
from sklearn import svm
X = [[0, 0], [1, 1], [1, 0]]
y = [0, 1, 1]
clf = svm.SVC() # class
clf.fit(X, y)
result = clf.predict([2, 2])
print(result) # target
报错:
ValueError: Expected 2D array, got 1D array instead:array=[ 2. 2.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
请问:1.到底啥问题? 2.怎么写才对? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询