sklearn的画图

from sklearn.metrics import roc_curve
fpr, tpr, thresholds=roc_curve(y_train_5, y_scores)
fpr, tpr
>>>
(array([0.00000000e+00, 0.00000000e+00, 1.83220653e-05, ..., 9.94686601e-01, 9.94686601e-01, 1.00000000e+00]), array([1.84467810e-04, 1.43884892e-02, 1.43884892e-02, ..., 9.99815532e-01, 1.00000000e+00, 1.00000000e+00]))
 
def plot_roc_curve(fpr, tpr, label=None):
#绘制下图的红线,fpr和tpr是横纵坐标集合;color代表线的颜色;linestyle是线的形状(虚线,实线等);
plt.plot(fpr, tpr, color='r',linestyle='-', linewidth=2, label=label)
# 绘制途中黑线,"k"代表黑色,"--"代表是虚线,两个[0,1]意义和上一行的fpr,tpr一致,就是代表x点集合以及y点集合,这里其实就是指定了两个点(0, 0)以及(1, 1)
plt.plot([0,1], [0,1], 'k--')
plt.axis([0,1,0,1]) # x轴取值范围为0-1,y轴取值范围是0-1
plt.xlabel("False Positive Rate") #X轴显示标签
plt.ylabel("True Positive Rate") #Y轴显示标签
 
#fpr和tpr是代表横纵坐标的集合,每个fpr元素对应一个tpr元素,组成了上图这个2D线性图形;
plot_roc_curve(fpr, tpr)
plt.show()
 

猜你喜欢

转载自www.cnblogs.com/xiashiwendao/p/9174538.html