第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Expected 2D array, got 1D array 相反,在將 1D 數(shù)組轉(zhuǎn)換為 2D

Expected 2D array, got 1D array 相反,在將 1D 數(shù)組轉(zhuǎn)換為 2D

素胚勾勒不出你 2022-04-27 13:38:24
我查看了其他答案,但仍然無法理解為什么問題仍然存在。Iris 數(shù)據(jù)集的經(jīng)典機器學習實踐。代碼:dataset=load_iris()X = np.array(dataset.data)y = np.array(dataset.target)X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)model = KNeighborsClassifier()model.fit(X_train, y_train)prediction=model.predict(X_test)所有數(shù)組的形狀:X 形狀:(150, 4)y 形狀:(150,)X_train: (105, 4)X_test: (45, 4)y_train: (105,)y_test(45,)預測:(45,)試圖打印這個model.score(y_test, prediction)我得到了錯誤。我嘗試使用 .reshape(-1,1) 將 y_test 和預測轉(zhuǎn)換為二維數(shù)組,但出現(xiàn)另一個錯誤:查詢數(shù)據(jù)維度必須與訓練數(shù)據(jù)維度匹配。這不僅關乎解決方案,還關乎理解問題所在。
查看完整描述

1 回答

?
GCT1015

TA貢獻1827條經(jīng)驗 獲得超4個贊

查看您使用的函數(shù)的簽名和文檔字符串通常很有用。model.score例如有


Parameters

----------

X : array-like, shape = (n_samples, n_features)

    Test samples.


y : array-like, shape = (n_samples) or (n_samples, n_outputs)

    True labels for X.

在文檔字符串中向您顯示您應該提供的確切輸入類型。


在這里你會做model.score(X_test, y_test)


model.score將同時進行預測X_test和比較y_test


查看完整回答
反對 回復 2022-04-27
  • 1 回答
  • 0 關注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號