亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ValueError:發現樣本數量不一致的輸入變量:[218, 30]

ValueError:發現樣本數量不一致的輸入變量:[218, 30]

慕姐4208626 2023-06-13 10:42:01
我正在使用線性 SVC 進行一些面部識別訓練,我的數據集是 870x22。我有 29 個不同的人的 30 幀,我在圖像中使用 22 個簡單值像素來識別面部圖像,說 22 個像素是我的特征。此外,當我調用 train_test_split() 時,它會給我一個大小為 218x22 的 X_test 和大小為 218 的 y_test。一旦我訓練了分類器并嘗試運行新面孔 (30x22) 矩陣的圖像,它就會給我錯誤:ValueError: Found input variables with inconsistent numbers of samples: [218, 30]這是代碼:import sklearnfrom sklearn.model_selection import train_test_splitfrom sklearn import metricsfrom sklearn.svm import SVCfrom sklearn.metrics import confusion_matrixfrom sklearn.metrics import accuracy_score, f1_score? ? img_amount = 30? ? target = np.asarray([1]*img_amount + [2]*img_amount + [3]*img_amount + [4]*img_amount + [5]*img_amount + [6]*img_amount + [7]*img_amount + [8]*img_amount + [9]*img_amount + [10]*img_amount + [11]*img_amount + [12]*img_amount + [13]*img_amount + [14]*img_amount + [15]*img_amount + [16]*img_amount + [17]*img_amount + [18]*img_amount + [19]*img_amount + [20]*img_amount + [21]*img_amount + [22]*img_amount + [23]*img_amount + [24]*img_amount + [25]*img_amount + [26]*img_amount + [27]*img_amount + [28]*img_amount + [29]*img_amount)? ?? ? dataset= dataset[:, 0:22]? ? ? ??? ? ? ? svc_1 = SVC(kernel='linear', C=0.00005)? ? ? ? X_train, X_test, y_train, y_test = train_test_split( dataset, target, test_size=0.25, random_state=0)? ? ? ??? ? ? ? def train(clf, X_train, X_test, y_train, y_test):? ? ? ? ? ??? ? ? ? ? ? clf.fit(X_train, y_train)? ? ? ? ? ? print ("Accuracy on training set:")? ? ? ? ? ? print (clf.score(X_train, y_train))? ? ? ? ? ? print ("Accuracy on testing set:")? ? ? ? ? ? print (clf.score(X_test, y_test))? ? ? ? ? ??? ? ? ? ? ? y_pred = clf.predict(X_test)? ? ? ? ? ??? ? ? ? ? ? print ("Classification Report:")? ? ? ? ? ? print (metrics.classification_report(y_test, y_pred))? ? ? ? ? ? print ("Confusion Matrix:")? ? ? ? ? ? print (metrics.confusion_matrix(y_test, y_pred))
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

這是問題所在:


predictions = svc_1.predict(new_face_image) 

print ("Confusion Matrix:")

print (metrics.confusion_matrix(y_test, predictions))

您正在預測 new_face_image 并使用您的測試數據集對其進行預測。


predictions = svc_1.predict(new_face_image) 

# change this to what you expect but shape=(30,)

expected=np.ones(len(new_face_image))

print ("Confusion Matrix:")

print (metrics.confusion_matrix(expected, predictions))

編輯以使用數據集測試數據進行驗證:


predictions = svc_1.predict(x_test) 

print ("Confusion Matrix:")

print (metrics.confusion_matrix(y_test, predictions))


查看完整回答
反對 回復 2023-06-13
  • 1 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號