import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
# Example true labels and predicted probabilities
# Replace these with your actual data
y_true = np.array([0, 0, 1, 1, 0, 1, 0, 1, 1, 0]) # True labels
y_scores = np.array([0.1, 0.4, 0.35, 0.8, 0.7, 0.9, 0.2, 0.65, 0.85, 0.5]) # Predicted probabilities
# Calculate TPR and FPR
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
roc_auc = auc(fpr, tpr) # Calculate AUC
# Plotting the ROC curve
plt.figure(figsize=(8, 6))
plt.plot(fpr, tpr, color='blue', lw=2, label='ROC curve (AUC = {:.2f})'.format(roc_auc))
plt.plot([0, 1], [0, 1], color='grey', linestyle='--') # Diagonal line (random chance)
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver Operating Characteristic (ROC) Curve')
plt.legend(loc='lower right')
plt.grid()
plt.show()
aW1wb3J0IG51bXB5IGFzIG5wCmltcG9ydCBtYXRwbG90bGliLnB5cGxvdCBhcyBwbHQKZnJvbSBza2xlYXJuLm1ldHJpY3MgaW1wb3J0IHJvY19jdXJ2ZSwgYXVjCgojIEV4YW1wbGUgdHJ1ZSBsYWJlbHMgYW5kIHByZWRpY3RlZCBwcm9iYWJpbGl0aWVzCiMgUmVwbGFjZSB0aGVzZSB3aXRoIHlvdXIgYWN0dWFsIGRhdGEKeV90cnVlID0gbnAuYXJyYXkoWzAsIDAsIDEsIDEsIDAsIDEsIDAsIDEsIDEsIDBdKSAgIyBUcnVlIGxhYmVscwp5X3Njb3JlcyA9IG5wLmFycmF5KFswLjEsIDAuNCwgMC4zNSwgMC44LCAwLjcsIDAuOSwgMC4yLCAwLjY1LCAwLjg1LCAwLjVdKSAgIyBQcmVkaWN0ZWQgcHJvYmFiaWxpdGllcwoKIyBDYWxjdWxhdGUgVFBSIGFuZCBGUFIKZnByLCB0cHIsIHRocmVzaG9sZHMgPSByb2NfY3VydmUoe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