S.H
S.H

Reputation: 137

Plot multiple ROC from multiple column values

Assuming I have retrieved 3 arrays from 3 columns in a csv file which are:

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

How can I plot 2 ROCs such that y1 vs y2 and y1 vs y3 (in sklearn)?

Upvotes: 1

Views: 2139

Answers (1)

Shahram
Shahram

Reputation: 814

Assuming y1 is your label and y2 and y3 are your scores below code should do it:

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()

Upvotes: 1

Related Questions