婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > Matplotlib繪制混淆矩陣的實(shí)現(xiàn)

Matplotlib繪制混淆矩陣的實(shí)現(xiàn)

熱門(mén)標(biāo)簽:河北防封卡電銷(xiāo)卡 開(kāi)封語(yǔ)音外呼系統(tǒng)代理商 地圖標(biāo)注線(xiàn)上如何操作 開(kāi)封自動(dòng)外呼系統(tǒng)怎么收費(fèi) 400電話(huà)辦理哪種 手機(jī)網(wǎng)頁(yè)嵌入地圖標(biāo)注位置 電銷(xiāo)機(jī)器人的風(fēng)險(xiǎn) 應(yīng)電話(huà)機(jī)器人打電話(huà)違法嗎 天津電話(huà)機(jī)器人公司

對(duì)于機(jī)器學(xué)習(xí)多分類(lèi)模型來(lái)說(shuō),其評(píng)價(jià)指標(biāo)除了精度之外,常用的還有混淆矩陣和分類(lèi)報(bào)告,下面來(lái)展示一下如何繪制混淆矩陣,這在論文中經(jīng)常會(huì)用到。

代碼如下:

import itertools
import matplotlib.pyplot as plt
import numpy as np
# 繪制混淆矩陣
def plot_confusion_matrix(cm, classes, normalize=False, title='Confusion matrix', cmap=plt.cm.Blues):
    """
    - cm : 計(jì)算出的混淆矩陣的值
    - classes : 混淆矩陣中每一行每一列對(duì)應(yīng)的列
    - normalize : True:顯示百分比, False:顯示個(gè)數(shù)
    """
    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
        print("顯示百分比:")
        np.set_printoptions(formatter={'float': '{: 0.2f}'.format})
        print(cm)
    else:
        print('顯示具體數(shù)字:')
        print(cm)
    plt.imshow(cm, interpolation='nearest', cmap=cmap)
    plt.title(title)
    plt.colorbar()
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation=45)
    plt.yticks(tick_marks, classes)
    # matplotlib版本問(wèn)題,如果不加下面這行代碼,則繪制的混淆矩陣上下只能顯示一半,有的版本的matplotlib不需要下面的代碼,分別試一下即可
    plt.ylim(len(classes) - 0.5, -0.5)
    fmt = '.2f' if normalize else 'd'
    thresh = cm.max() / 2.
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        plt.text(j, i, format(cm[i, j], fmt),
                 horizontalalignment="center",
                 color="white" if cm[i, j] > thresh else "black")
    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    plt.show()

測(cè)試數(shù)據(jù):

cnf_matrix = np.array([[8707, 64, 731, 164, 45],
                      [1821, 5530, 79, 0, 28],
                      [266, 167, 1982, 4, 2],
                      [691, 0, 107, 1930, 26],
                      [30, 0, 111, 17, 42]])
attack_types = ['Normal', 'DoS', 'Probe', 'R2L', 'U2R']

第一種情況:顯示百分比

plot_confusion_matrix(cnf_matrix, classes=attack_types, normalize=True, title='Normalized confusion matrix')

效果:


第二種情況:顯示數(shù)字

plot_confusion_matrix(cnf_matrix, classes=attack_types, normalize=False, title='Normalized confusion matrix')

效果:


到此這篇關(guān)于Matplotlib繪制混淆矩陣的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Matplotlib 混淆矩陣內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 利用python中的matplotlib打印混淆矩陣實(shí)例
  • Python使用matplotlib繪制正弦和余弦曲線(xiàn)的方法示例
  • Python matplotlib繪制圖形實(shí)例(包括點(diǎn),曲線(xiàn),注釋和箭頭)
  • matplotlib 曲線(xiàn)圖 和 折線(xiàn)圖 plt.plot()實(shí)例
  • Python matplotlib 繪制雙Y軸曲線(xiàn)圖的示例代碼
  • 使用matplotlib動(dòng)態(tài)刷新指定曲線(xiàn)實(shí)例
  • Python使用matplotlib繪制三維參數(shù)曲線(xiàn)操作示例
  • Python使用matplotlib繪制Logistic曲線(xiàn)操作示例
  • Python matplotlib畫(huà)曲線(xiàn)例題解析
  • matplotlib畫(huà)混淆矩陣與正確率曲線(xiàn)的實(shí)例代碼

標(biāo)簽:駐馬店 山東 成都 六盤(pán)水 宿遷 江蘇 常州 蘭州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Matplotlib繪制混淆矩陣的實(shí)現(xiàn)》,本文關(guān)鍵詞  Matplotlib,繪制,混淆,矩陣,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Matplotlib繪制混淆矩陣的實(shí)現(xiàn)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Matplotlib繪制混淆矩陣的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 尼木县| 综艺| 德庆县| 凤山市| 田东县| 民县| 东阳市| 宜州市| 上林县| 沂水县| 肇源县| 洛南县| 肇州县| 马山县| 平湖市| 石城县| 灵寿县| 汉中市| 镇沅| 文山县| 紫云| 林口县| 宜宾市| 青浦区| 石家庄市| 平邑县| 乡宁县| 会宁县| 重庆市| 松潘县| 嵩明县| 磐石市| 广水市| 称多县| 安吉县| 巩义市| 阳山县| 临颍县| 锦屏县| 明光市| 佛山市|