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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何構(gòu)建混淆矩陣?

如何構(gòu)建混淆矩陣?

qq_花開(kāi)花謝_0 2022-09-06 17:57:59
我有以下代碼,它繪制了KNN算法的嵌套與非嵌套交叉驗(yàn)證。# Number of random trialsNUM_TRIALS = 30# Load the datasetX_iris = X.valuesy_iris = y# Set up possible values of parameters to optimize overp_grid = {"n_neighbors": [1, 5, 10]}# We will use a Support Vector Classifier with "rbf" kernelsvm = KNeighborsClassifier()# Arrays to store scoresnon_nested_scores = np.zeros(NUM_TRIALS)nested_scores = np.zeros(NUM_TRIALS)# Loop for each trialfor i in range(NUM_TRIALS):    # Choose cross-validation techniques for the inner and outer loops,    # independently of the dataset.    # E.g "GroupKFold", "LeaveOneOut", "LeaveOneGroupOut", etc.    inner_cv = KFold(n_splits=4, shuffle=True, random_state=i)    outer_cv = KFold(n_splits=4, shuffle=True, random_state=i)    # Non_nested parameter search and scoring    clf = GridSearchCV(estimator=svm, param_grid=p_grid, cv=inner_cv)    clf.fit(X_iris, y_iris)    non_nested_scores[i] = clf.best_score_    # Nested CV with parameter optimization    nested_score = cross_val_score(clf, X=X_iris, y=y_iris, cv=outer_cv)    nested_scores[i] = nested_score.mean()score_difference = non_nested_scores - nested_scorespreds=clf.best_estimator_.predict(X_test)from sklearn.metrics import confusion_matrixcm = confusion_matrix(y_test, preds)one, two, three, four,five,six,seven,eight,nine = confusion_matrix(y_test, preds).ravel()我遇到的問(wèn)題是混淆矩陣?yán)L圖,我遇到了以下錯(cuò)誤:ValueError                                Traceback (most recent call last)<ipython-input-22-13536688e18b> in <module>()     45 from sklearn.metrics import confusion_matrix     46 cm = confusion_matrix(y_test, preds)---> 47 one, two, three, four,five,six,seven,eight,nine = confusion_matrix(y_test, preds).ravel()     48 cm = [[one,two],[three,four],[five,six],[seven,eight],[nine,eight]]     49 ax= plt.subplot()ValueError: too many values to unpack (expected 9)我不知道如何解決這個(gè)問(wèn)題。我的數(shù)據(jù)集中有 9 個(gè)目標(biāo)變量,存儲(chǔ)在 y 中。[11 11 11 ... 33 33 33] #the target variables being : 11,12,13,21,22,23,31,32,33
查看完整描述

1 回答

?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

混淆矩陣由“cm = confusion_matrix(y_test,preds)”構(gòu)建,其中cm是9x9矩陣(因?yàn)槟繕?biāo)變量中有9個(gè)不同的標(biāo)簽)。如果要繪制它,可以使用plot_confusion_matrix函數(shù)。沒(méi)有必要把它弄得亂七八糟。如果對(duì)其進(jìn)行處理,則 9x9 矩陣將轉(zhuǎn)換為 81 個(gè)值,并且您將它解壓縮為賦值左側(cè)的 9 個(gè)變量。這就是您收到“太多值無(wú)法解壓縮(預(yù)期9)”錯(cuò)誤的原因。


查看完整回答
反對(duì) 回復(fù) 2022-09-06
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)