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

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

將一維向量擬合到 SVC 線性內核

將一維向量擬合到 SVC 線性內核

慕容708150 2023-03-16 16:07:43
我正在嘗試將 SVC 與線性內核一起用于圖像識別任務。我當前的數據是一個 2x5 矩陣[['Face 1' 'Face2' 'Face 3' 'Face 4' 'Face 5'] ['229.0' '230.0' '231.0' '230.0' '230.0']]我的第二行是我的 X 特征,它們是來自不同圖像的像素強度值。我的第一行是我的 Y 標簽,它們是從中提取像素的面部圖像。我正在嘗試不惜一切代價將我的數據輸入 SVC。我正在嘗試的是:    m_array = [[229, 230, 231, 230, 230]]    faces = []    faces = np.asarray(['Face 1', 'Face2', 'Face 3', 'Face 4', 'Face 5']).reshape(-1, 5)        data = np.stack((faces, m_array)).reshape(2, 5)    df = pd.DataFrame(data)    X = data[1, :]    Y = data[0, :]from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)from sklearn.svm import SVCsvclassifier = SVC(kernel='linear')svclassifier.fit(X_train, y_train)我想測試這些功能的識別率,但出現錯誤:類型錯誤:單例數組 array(162) 不能被視為有效集合。
查看完整描述

1 回答

?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

sklearn 期望您的 X_train 數組是一個二維數組,例如 (n_examples, 1),而 Y_train 是一維標簽數組,例如 (n_examples, )。


我重新格式化了您的代碼以刪除一些不必要的步驟并解決了問題:


import numpy as np

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.svm import SVC


m_array = np.array([229, 230, 231, 230, 230])[:, np.newaxis]

faces = np.array(['Face 1', 'Face2', 'Face 3', 'Face 4', 'Face 5'])


X_train, X_test, y_train, y_test = train_test_split(m_array, faces, test_size = 0.20)


svclassifier = SVC(kernel='linear')

svclassifier.fit(X_train, y_train)


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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