y_predicted=bdt.predict(X_test)
from sklearn.metrics import confusion_matrix
from sklearn import cross_validation, metrics
import matplotlib.pyplot as plt
plt.rc('figure',figsize=(5,5))
cm = confusion_matrix(y_test,y_predicted)
plt.matshow(cm,cmap = plt.cm.Blues) # 背景颜色
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.title('Cart_train')
plt.show()
y_predprob = bdt.predict_proba(X_test)[:,1]
print("AUC Score (Train): %f" % metrics.roc_auc_score(y_test, y_predprob))
# 3.1> 画混淆矩阵
# 方法1:
# from cm_plot import *# 导入自行编写的混淆矩阵可视化函数 等价于下面的语句
# cm_plot(train[:,3],predict_CartResult).show()#显示混淆矩阵可视化结果
# 方法2:
# 导入相关库,生成混淆矩阵
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
plt.rc('figure',figsize=(5,5))
cm = confusion_matrix(train[:,3], predict_CartResult)
plt.matshow(cm,cmap = plt.cm.Blues) # 背景颜色
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.title('Cart_train')
plt.show()