[問題] SVM error 問題

看板Python作者 (gecer)時間4年前 (2020/02/08 19:23), 編輯推噓0(113)
留言5則, 5人參與, 4年前最新討論串1/1
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

02/08 20:11, 4年前 , 1F
他說要2D array, [[2, 0, 3]]這樣才算2D
02/08 20:11, 1F

02/09 08:39, 4年前 , 2F
你餵進去的資料是2維的 但是卻要預測1維的 當然會報錯
02/09 08:39, 2F

02/09 11:24, 4年前 , 3F
dimension 問題
02/09 11:24, 3F

02/10 16:35, 4年前 , 4F
sklearn網站上的範例就很清楚了 = =" 可以學著查一下
02/10 16:35, 4F

02/11 15:57, 4年前 , 5F
02/11 15:57, 5F
文章代碼(AID): #1UFfe_6M (Python)