从多个列值绘制多个ROC

2024-07-03 06:05:12 发布

您现在位置:Python中文网/ 问答频道 /正文

假设我从csv文件的3列中检索了3个数组,它们是:

y1=['1', '0', '0', '0', '1'];
y2=['1', '1', '1', '0', '0'];
y3=['0', '1', '1', '0', '1'];

如何绘制2个roc,使y1vsy2和{}vsy3(在sklearn中)?在


Tags: 文件csv绘制数组sklearnrocy1y2
1条回答
网友
1楼 · 发布于 2024-07-03 06:05:12

假设y1是你的标签,y2和y3是你的分数,下面的代码应该可以做到:

y1=[1, 0, 0, 0, 1];
y2=[1, 1, 0, 0, 1];
y3=[0, 0, 1, 0, 1];
from sklearn.metrics import *
import pandas as pd
import matplotlib.pyplot as plt

plt.figure(figsize=(14,10),dpi=640)
fpr, tpr, thresholds = roc_curve(y1, y2)
auc1 = auc(fpr,tpr)

plt.plot(fpr, tpr,label="AUC Y2:{0}".format(auc1),color='red', linewidth=2)

fpr, tpr, thresholds = roc_curve(y1, y3)
auc1 = auc(fpr,tpr)

plt.plot(fpr, tpr,label="AUC Y3:{0}".format(auc1),color='blue', 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('ROC') 
plt.grid(True)
plt.legend(loc="lower right")
plt.show()

相关问题 更多 >