1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 不同模型的ROC曲线 lable_names = ["逻辑回归","SVM","神经网络","随机森林","决策树"] # 模型名称 colors = ["r","b","g","m","k",] # 不同曲线颜色 linestyles =["-", "--", "-.", ":", "-"] #不同曲线 fig = plt.figure(figsize=(8,7),dpi=150) for n in range(5): ## 计算绘制ROC曲线的取值 plt.plot(fpr[n], tpr[n],color=colors[n],linewidth = 2, linestyle = linestyles[n], label = f'AUC={auc[n]} '+lable_names[n]) plt.plot([0, 1], [0, 1], 'k--') plt.xlabel("假正率"); plt.ylabel("真正率") plt.xlim(0, 1); plt.ylim(0, 1) plt.grid() plt.legend() plt.title("不同模型的ROC曲线") ## 放大的图片 inset_ax = fig.add_axes([0.3, 0.45, 0.4, 0.4],facecolor="white") for n in range(5): ## 放大的图 inset_ax.plot(fpr[n], tpr[n],color=colors[n],linewidth = 2,linestyle = linestyles[n], label = f'AUC={auc[n]} '+lable_names[n]) inset_ax.set_xlim([-0.1,1]) inset_ax.set_ylim([0.7,1.01]) inset_ax.grid() plt.show() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # 残差图——检验自相关 def e_picture_auto(self): #创建画布 fig = plt.figure(figsize=(8, 8)) #使用axisartist.Subplot方法创建一个绘图区对象ax ax = axisartist.Subplot(fig, 111) #将绘图区对象添加到画布中 fig.add_axes(ax) #通过set_visible方法设置绘图区所有坐标轴隐藏 ax.axis[:].set_visible(False) #ax.new_floating_axis代表添加新的坐标轴 ax.axis["x"] = ax.new_floating_axis(0,0) #给x坐标轴加上箭头 ax.axis["x"].set_axisline_style("->", size = 1.0) #添加y坐标轴,且加上箭头 ax.axis["y"] = ax.new_floating_axis(1,0) ax.axis["y"].set_axisline_style("-|>", size = 1.0) #设置x、y轴上刻度显示方向 ax.axis["x"].set_axis_direction("top") ax.axis["y"].set_axis_direction("right") plt.scatter(self.e.values[:-1],self.e.values[1:], marker='.') # 标注某个点 plt.annotate("异常值", (-7,63), xycoords='data',xytext=(-20, 55),arrowprops=dict(arrowstyle='->'),fontsize=15) plt.annotate("异常值", (63,-8), xycoords='data',xytext=(45, -8),arrowprops=dict(arrowstyle='->'),fontsize=15) plt.annotate(r"$e_t$", (-3,67), xycoords='data',xytext=(-4,67),fontsize=15) # ,arrowprops=dict(arrowstyle='-') # y标签 plt.annotate(r"$e_{t-1}$", (67,5), xycoords='data',xytext=(67,-4),fontsize=15) # x标签 plt.annotate(r"$O$", (67,5), xycoords='data',xytext=(-3,2),fontsize=15) # 原坐标标签 # 局部放大图 inset_ax = fig.add_axes([0.45, 0.45, 0.4, 0.4],facecolor="white") ## 放大的图 inset_ax.scatter(self.e.values[:-1],self.e.values[1:]) inset_ax.set_xlim([-12,5]) inset_ax.set_ylim([-12,5]) inset_ax.annotate("", (-11,0), xycoords='data',arrowprops=dict(arrowstyle='<-'),xytext=(5,0),fontsize=12) # 添加原坐标标签# inset_ax.axhline(y=0,c="black", lw=0.5) # 添加水平线 inset_ax.annotate("", (0,-11), xycoords='data',arrowprops=dict(arrowstyle='<-'),xytext=(0,4),fontsize=12)# inset_ax.axvline(x=0,c="black", lw=0.5) # 添加纵轴线 inset_ax.annotate(r"$O$", (-1,0.5), xycoords='data',xytext=(-1,0.5),fontsize=12) # 添加原坐标标签 inset_ax.spines['right'].set_visible(False) inset_ax.spines['top'].set_visible(False) inset_ax.text(-10,4, '局部放大图', bbox=dict(facecolor='yellow', alpha=0.5), fontsize=15) # 添加文本 |