主頁 > 知識(shí)庫 > matplotlib畫混淆矩陣與正確率曲線的實(shí)例代碼

matplotlib畫混淆矩陣與正確率曲線的實(shí)例代碼

熱門標(biāo)簽:檢查注冊(cè)表項(xiàng) 網(wǎng)站文章發(fā)布 銀行業(yè)務(wù) 呼叫中心市場(chǎng)需求 美圖手機(jī) 服務(wù)器配置 鐵路電話系統(tǒng) 智能手機(jī)

混淆矩陣    

混淆矩陣(Confusion Matrix)是機(jī)器學(xué)習(xí)中用來總結(jié)分類模型預(yù)測(cè)結(jié)果的一個(gè)分析表,是模式識(shí)別領(lǐng)域中的一種常用的表達(dá)形式。它以矩陣的形式描繪樣本數(shù)據(jù)的真實(shí)屬性和分類預(yù)測(cè)結(jié)果類型之間的關(guān)系,是用來評(píng)價(jià)分類器性能的一種常用方法。

我們可以通過一個(gè)簡(jiǎn)單的例子來直觀理解混淆矩陣

#!/usr/bin/python3.5
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['FangSong']  #可顯示中文字符
plt.rcParams['axes.unicode_minus']=False
classes = ['a','b','c','d','e','f','g']
confusion_matrix = np.array([(99,1,2,2,0,0,6),(1,98,7,6,2,1,1),(0,0,86,0,0,2,0),(0,0,0,86,1,0,0),(0,0,0,1,94,1,0),(0,1,5,1,0,96,8),(0,0,0,4,3,0,85)],dtype=np.float64)
 
plt.imshow(confusion_matrix, interpolation='nearest', cmap=plt.cm.Oranges)  #按照像素顯示出矩陣
plt.title('混淆矩陣')
plt.colorbar()
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=-45)
plt.yticks(tick_marks, classes)
 
thresh = confusion_matrix.max() / 2.
#iters = [[i,j] for i in range(len(classes)) for j in range((classes))]
#ij配對(duì),遍歷矩陣迭代器
iters = np.reshape([[[i,j] for j in range(7)] for i in range(7)],(confusion_matrix.size,2))
for i, j in iters:
    plt.text(j, i, format(confusion_matrix[i, j]),fontsize=7)   #顯示對(duì)應(yīng)的數(shù)字
 
plt.ylabel('真實(shí)類別')
plt.xlabel('預(yù)測(cè)類別')
plt.tight_layout()
plt.show()

正確率曲線 

    fig ,ax= plt.subplots()
    plt.plot(np.arange(iterations), fig_acc,'b')
    plt.plot(np.arange(iterations), fig_realacc, 'r')
    ax.set_xlabel('迭代次數(shù)')
    ax.set_ylabel('正確率(%)')
 
    labels = ["訓(xùn)練正確率", "測(cè)試正確率"]
    # labels = [l.get_label() for l in lns]
    plt.legend( labels, loc=7)
    plt.show()

總結(jié)

到此這篇關(guān)于matplotlib畫混淆矩陣與正確率曲線的文章就介紹到這了,更多相關(guān)matplotlib畫混淆矩陣內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

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

標(biāo)簽:樂山 上海 河南 長(zhǎng)治 沈陽 新疆 滄州 紅河

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《matplotlib畫混淆矩陣與正確率曲線的實(shí)例代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266