MCPcopy Create free account
hub / github.com/Jack-Cherish/Machine-Learning / plotROC

Function plotROC

AdaBoost/ROC.py:120–154  ·  view source on GitHub ↗

绘制ROC Parameters: predStrengths - 分类器的预测强度 classLabels - 类别 Returns: 无

(predStrengths, classLabels)

Source from the content-addressed store, hash-verified

118
119
120def plotROC(predStrengths, classLabels):
121 """
122 绘制ROC
123 Parameters:
124 predStrengths - 分类器的预测强度
125 classLabels - 类别
126 Returns:
127
128 """
129 font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
130 cur = (1.0, 1.0) #绘制光标的位置
131 ySum = 0.0 #用于计算AUC
132 numPosClas = np.sum(np.array(classLabels) == 1.0) #统计正类的数量
133 yStep = 1 / float(numPosClas) #y轴步长
134 xStep = 1 / float(len(classLabels) - numPosClas) #x轴步长
135
136 sortedIndicies = predStrengths.argsort() #预测强度排序,从低到高
137 fig = plt.figure()
138 fig.clf()
139 ax = plt.subplot(111)
140 for index in sortedIndicies.tolist()[0]:
141 if classLabels[index] == 1.0:
142 delX = 0; delY = yStep
143 else:
144 delX = xStep; delY = 0
145 ySum += cur[1] #高度累加
146 ax.plot([cur[0], cur[0] - delX], [cur[1], cur[1] - delY], c = 'b') #绘制ROC
147 cur = (cur[0] - delX, cur[1] - delY) #更新绘制光标的位置
148 ax.plot([0,1], [0,1], 'b--')
149 plt.title('AdaBoost马疝病检测系统的ROC曲线', FontProperties = font)
150 plt.xlabel('假阳率', FontProperties = font)
151 plt.ylabel('真阳率', FontProperties = font)
152 ax.axis([0, 1, 0, 1])
153 print('AUC面积为:', ySum * xStep) #计算AUC
154 plt.show()
155
156
157if __name__ == '__main__':

Callers 1

ROC.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected