作者gecer (gecer)
看板Python
標題[問題] SVM error 問題
時間Sat Feb 8 19:23:41 2020
from sklearn import svm
x = [[2,0,1],[1,1,2],[2,3,3]]
y = [0,0,1] #分類標記
clf = svm.SVC(kernel = 'linear') #SVM模組,svc,線性核函式
clf.fit(x,y)
print(clf)
print(clf.support_vectors_) #支援向量點
print(clf.support_) #支援向量點的索引
print(clf.n_support_) #每個class有幾個支援向量點
print(clf.predict([2,0,3])) #預測
小弟執行上列code 出現下列error
ValueError: Expected 2D array, got 1D array instead:
array=[2. 0. 3.].
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.
不能理解為什麼print(clf.predict([2,0,3])) 會有錯誤??
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.47.31.250 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1581161023.A.196.html
→ Mchord: 他說要2D array, [[2, 0, 3]]這樣才算2D 02/08 20:11
→ max36067: 你餵進去的資料是2維的 但是卻要預測1維的 當然會報錯 02/09 08:39
→ Pieteacher: dimension 問題 02/09 11:24
推 ctr1: sklearn網站上的範例就很清楚了 = =" 可以學著查一下 02/10 16:35
噓 leo021566: 唉 02/11 15:57
推 erre: 你要學掰陳,抓別人程式只要改參數就好,其他不要動 09/03 11:49