通过实例来讲解Python脚本来实现构建ROC曲线图。
步骤:
1、下载模块: matplotlib、numpy
2、准备数据:
例如:a.txt,内容如下
0.87,0.000001
0.87,0.000003
0.92,0.000006
0.93,0.000011
0.94,0.000017
0.94,0.000028
0.94,0.000044
3、编写脚本:a.py
#coding:utf-8
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from matplotlib.font_manager import FontProperties
import matplotlib as mpl
#指定默认字体
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['font.family']='sans-serif'
#解决负号'-'显示为方块的问题
mpl.rcParams['axes.unicode_minus'] = False
a_y, a_x = np.loadtxt('a.txt', delimiter=',', unpack=True)
plt.plot(a_x,a_y,label='a',color='green')
plt.plot(a_x,a_y,color='green')
p