# #-*- 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)