<jupyter_start><jupyter_text>ROC Curve<jupyter_code>from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt

y_true = [0, 1, 1, 1, 1, 0, 1, 1, 0, 0]

# random probability of each model A and B
a_prob = [0.6, 0.7, 0.7, 0.8, 0.9, 0.7, 0.85, 0.7, 0.65, 0.75]
b_prob = [0.05, 0.05, 0.1, 0.3, 0.6, 0.3, 0.4, 0.5, 0.2, 0.1]
# probability of perfact model C
c_prob = [0, 1, 1, 1, 1, 0, 1, 1, 0, 0]

# false_positive_rate, true_positive_rate, threshold
fpr_a, tpr_a, thr_a = roc_curve(y_true, a_prob)
fpr_b, tpr_b, thr_b = roc_curve(y_true, b_prob)
fpr_c, tpr_c, thr_c = roc_curve(y_true, c_prob)

# area under curve
auc_a = auc(fpr_a, tpr_a)
auc_b = auc(fpr_b, tpr_b)
auc_c = auc(fpr_c, tpr_c)

# drawing plot
plt.xlabel("False Positive Rate")
plt.ylabel("True Positive Rate")
plt.title("ROC Curve")

plt.plot(fpr_a, tpr_a, label=f"ROC curve area = {auc_a:.2f}")
plt.plot(fpr_b, tpr_b, label=f"ROC curve area = {auc_b:.2f}")
plt.plot(fpr_c, tpr_c, label=f"ROC curve area = {auc_c:.2f}")

plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup