我试图根据以下输入df1和ROC_输入计算指标和ROC-AUC分数。 当所有四种度量类型中都有一些值时,下面的代码可以正常工作,但如果某些度量值为零,我会遇到零除法问题或ROC-AUC分数为1。我应该如何解决这个问题
df1
TP= 0
FN= 673
TN= 826
FP= 0
代码
def metrics(self, tp, fp, tn, fn):
sensitivity = tp / (tp+fn),
specificity = tn / (tn+fp),
precision = tp / (tp+fp),
recall = tn / (tn+fn),
return sensitivity, specificity, precision, recall
roc_输入
link下载数据
代码
def roc_plot(self, roc_input):
n_classes = 2
y_test = np.array(roc_input['y_test'], dtype=int)
y_score = np.array(roc_input['y_score'], dtype=int)
plt.figure(figsize=(5,5))
fpr, tpr, thresholds = roc_curve(y_test, y_score)
auc1 = auc(fpr,tpr)
plt.plot(fpr, tpr,label='AUC = %0.2f)' % auc1, color='red', linewidth=2)
plt.plot([0, 1], [0, 1], 'k--', lw=1)
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title(myphd_id)
plt.grid(True)
plt.legend(loc="lower right")
plt.tight_layout()
return auc1
目前没有回答
相关问题 更多 >
编程相关推荐