Run ❯
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
#Three lines to make our compiler able to draw: import sys import matplotlib matplotlib.use('Agg') import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import accuracy_score, confusion_matrix, roc_auc_score, roc_curve n = 10000 ratio = .95 n_0 = int((1-ratio) * n) n_1 = int(ratio * n) y = np.array([0] * n_0 + [1] * n_1) # below are the probabilities obtained from a hypothetical model that doesn't always predict the mode y_proba_2 = np.array( np.random.uniform(0, .7, n_0).tolist() + np.random.uniform(.3, 1, n_1).tolist() ) y_pred_2 = y_proba_2 > .5 def plot_roc_curve(true_y, y_prob): """ plots the roc curve based of the probabilities """ fpr, tpr, thresholds = roc_curve(true_y, y_prob) plt.plot(fpr, tpr) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plot_roc_curve(y, y_proba_2) print(f'model 2 AUC score: {roc_auc_score(y, y_proba_2)}') #Two lines to make our compiler able to draw: plt.savefig(sys.stdout.buffer) sys.stdout.flush()
model 2 AUC score: 0.8270551578947367