【发布时间】:2020-05-05 02:57:27
【问题描述】:
如何在 Python 中为多个患者的 CNN 模型绘制 ROC 曲线?
当我运行我的代码时,我得到了一个空图。我该如何解决这个错误?
acc=0
fp=0
tp=0
fn=0
lastTenResult=list()
for el in interPrediction:
if(el[1]>0.5):
acc=acc+1
lastTenResult.append(1)
else:
lastTenResult.append(0)
if(len(lastTenResult)>10):
acc=acc-lastTenResult.pop(0)
if(acc>=8):
fp=fp+1
lastTenResult=list()
acc=0
lastTenResult=list()
for el in preictPrediction:
if(el[1]>0.5):
acc=acc+1
lastTenResult.append(1)
else:
lastTenResult.append(0)
if(len(lastTenResult)>10):
acc=acc-lastTenResult.pop(0)
if(acc>=8):
tp=tp+1
else:
if(len(lastTenResult)==10):
fn=fn+1
sensitivity=tp/(tp+fn)
FPR=fp/(secondsInterictalInTest/(60*60))
TPR=tp/(tp + fn)
result=result+str(i+1)+','+str(tp)+','+str(fp)+','+str(fn)+','+str(secondsInterictalInTest)+','
result=result+str(sensitivity)+','+str(FPR)+'\n'
print('True Positive, False Positive, False negative, Second of Inter in Test, Sensitivity, FPR')
print(str(tp)+','+str(fp)+','+str(fn)+','+str(secondsInterictalInTest)+','+str(sensitivity)+','+str(FPR))
with open(OutputPath, "a+") as myfile:
myfile.write(result)
x =FPR # false_positive_rate
y =TPR # true_positive_rate
# This is the ROC curve
plt.plot(x,y)
plt.show()
【问题讨论】:
-
使用sklearn
标签: python machine-learning plot deep-learning roc