CNN模型的ROC曲线图

问题描述 投票:0回答:1

[如何为许多患者使用CNN模型在Python中绘制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()
python machine-learning plot deep-learning roc
1个回答
0
投票

[首先,您介意验证xy都是带有NA的数值列表吗?如果是这样,那么您可以尝试发起这样的数字吗?

import matplotlib.pyplot as plt
plt.figure() #             <---------------------------
plt.plot(x,y, label="XXX")
plt.plot([0,1], [0,1], 'r--')
pltt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.show()

sklearn中的某些功能可以使您轻松完成它。

from sklearn.metrics import roc_aus_score
from sklearn.metrics import roc_curve

FPR, TPR, thresholds = roc_curve(Y)

希望它对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.