机器学习-混淆矩阵的画图方法

# #-*- coding: utf-8 -*-
def cm_plot(y, yp):
    from sklearn.metrics import confusion_matrix
    cm = confusion_matrix(y, yp)
    import matplotlib.pyplot as plt
    plt.matshow(cm, cmap=plt.cm.Greens)
    plt.colorbar()
    for x in range(len(cm)):
        for y in range(len(cm)):
            plt.annotate(cm[x, y], xy=(x, y), horizontalalignment='center', verticalalignment='center')
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    plt.show()
def my_confusion_matrix(y_true, y_pred):
    from sklearn.metrics import confusion_matrix
    labels = list(set(y_true))
    conf_mat = confusion_matrix(y_true, y_pred, labels = labels)
    # print "confusion_matrix(left labels: y_true, up labels: y_pred):"
    # print "labels\t",
    for i in range(len(labels)):
        print (labels[i],"\t",)
    for i in range(len(conf_mat)):
        # print i,"\t",
        for j in range(len(conf_mat[i])):
            print (conf_mat[i][j],'\t',)
#coding:utf-8
#网址:http://scikit-plot.readthedocs.io/en/stable/apidocs.html#scikitplot.clustering_factory
from sklearn.datasets import load_digits
import matplotlib.pyplot as plt
from scikitplot import classifier_factory
X,y = load_digits(return_X_y=True)

from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(n_estimators=5,max_depth=5,random_state=1)
import scikitplot.plotters as skplt
skplt.plot_learning_curve(clf,X,y) #学习率曲线

clf.fit(X,y)
classifier_factory(clf)
clf.plot_confusion_matrix(X,y,normalize = True) # 混淆矩阵
clf.plot_roc_curve(X,y) #roc曲线
clf.plot_precision_recall_curve(X,y)  #recall 曲线
skplt.plot_feature_importances(clf)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值