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

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

混淆矩陣錯(cuò)誤“分類指標(biāo)無法處理多標(biāo)簽指標(biāo)和多類目標(biāo)的混合”

混淆矩陣錯(cuò)誤“分類指標(biāo)無法處理多標(biāo)簽指標(biāo)和多類目標(biāo)的混合”

躍然一笑 2021-11-02 16:47:02
我得到一個(gè)Classification metrics can't handle a mix of multilabel-indicator and multiclass targets當(dāng)我嘗試使用混淆矩陣時(shí)出錯(cuò)。我正在做我的第一個(gè)深度學(xué)習(xí)項(xiàng)目。我是新手。我正在使用由 keras 提供的 mnist 數(shù)據(jù)集。我已經(jīng)成功地訓(xùn)練和測試了我的模型。但是,當(dāng)我嘗試使用 scikit learn 混淆矩陣時(shí),我收到了上述錯(cuò)誤。我已經(jīng)搜索了一個(gè)答案,雖然有關(guān)于這個(gè)錯(cuò)誤的答案,但沒有一個(gè)對我有用。從我在網(wǎng)上找到的內(nèi)容來看,它可能與損失函數(shù)有關(guān)(我categorical_crossentropy在我的代碼中使用了)。我嘗試將其更改為,sparse_categorical_crossentropy但這只是給了我Error when checking target: expected dense_2 to have shape (1,) but got array with shape (10,)當(dāng)我fit()在模型上運(yùn)行該函數(shù)時(shí)。這是代碼。(為簡潔起見,我省略了進(jìn)口)model = Sequential()model.add(Dense(512, activation='relu', input_shape=(28 * 28,)))model.add(Dense(10, activation='softmax')) model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])(train_images, train_labels), (test_images, test_labels) = mnist.load_data()train_images = train_images.reshape((60000, 28 * 28))train_images = train_images.astype('float32') / 255test_images = test_images.reshape((10000, 28 * 28))test_images = test_images.astype('float32') / 255train_labels = to_categorical(train_labels)test_labels = to_categorical(test_labels)model.fit(train_images, train_labels, epochs=10, batch_size=128)rounded_predictions = model.predict_classes(test_images, batch_size=128, verbose=0)cm = confusion_matrix(test_labels, rounded_predictions)我怎樣才能解決這個(gè)問題?
查看完整描述

2 回答

?
千萬里不及你

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

混淆矩陣需要將標(biāo)簽和預(yù)測作為個(gè)位數(shù),而不是作為單熱編碼向量;盡管您已經(jīng)使用model.predict_classes(),即


rounded_predictions = model.predict_classes(test_images, batch_size=128, verbose=0)

rounded_predictions[1]

# 2

你test_labels仍然是one-hot編碼:


test_labels[1]

# array([0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)

因此,您也應(yīng)該將它們轉(zhuǎn)換為個(gè)位數(shù),如下所示:


import numpy as np

rounded_labels=np.argmax(test_labels, axis=1)

rounded_labels[1]

# 2

之后,混淆矩陣應(yīng)該會出現(xiàn):


from sklearn.metrics import confusion_matrix

cm = confusion_matrix(rounded_labels, rounded_predictions)

cm

# result:

array([[ 971,    0,    0,    2,    1,    0,    2,    1,    3,    0],

       [   0, 1121,    2,    1,    0,    1,    3,    0,    7,    0],

       [   5,    4,  990,    7,    5,    3,    2,    7,    9,    0],

       [   0,    0,    0,  992,    0,    2,    0,    7,    7,    2],

       [   2,    0,    2,    0,  956,    0,    3,    3,    2,   14],

       [   3,    0,    0,   10,    1,  872,    3,    0,    1,    2],

       [   5,    3,    1,    1,    9,   10,  926,    0,    3,    0],

       [   0,    7,   10,    1,    0,    2,    0,  997,    1,   10],

       [   5,    0,    3,    7,    5,    7,    3,    4,  937,    3],

       [   5,    5,    0,    9,   10,    3,    0,    8,    3,  966]])


查看完整回答
反對 回復(fù) 2021-11-02
  • 2 回答
  • 0 關(guān)注
  • 514 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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