Every line of 'roc auc curve' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
363 def auc(self): 364 if self.type != DatasetType.binary: 365 # raise ValueError("AUC metric is only supported for binary classification: {}.".format(self.classes)) 366 log.warning("AUC metric is only supported for binary classification: %s.", self.classes) 367 return nan 368 return float(roc_auc_score(self.truth, self.probabilities[:, 1]))
654 def calc_auc(x, y): 655 """ Given x and y values it calculates the approx. integral and normalizes it: area under curve""" 656 integral = np.trapz(y, x) 657 norm = np.trapz(np.ones_like(y), x) 658 659 return integral / norm
109 def plot_roc(y_test, y_pred, label=''): 110 """Compute ROC curve and ROC area""" 111 112 fpr, tpr, _ = roc_curve(y_test, y_pred) 113 roc_auc = auc(fpr, tpr) 114 115 # Plot of a ROC curve for a specific class 116 plt.figure() 117 plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc) 118 plt.plot([0, 1], [0, 1], 'k--') 119 plt.xlim([0.0, 1.0]) 120 plt.ylim([0.0, 1.05]) 121 plt.xlabel('False Positive Rate') 122 plt.ylabel('True Positive Rate') 123 plt.title('Receiver operating characteristic' + label) 124 plt.legend(loc="lower right") 125 plt.show()
19 def auc_score(y_true, y_pred, positive_label=1): 20 if hasattr(sklearn.metrics, 'roc_auc_score'): 21 return sklearn.metrics.roc_auc_score(y_true, y_pred) 22 23 fp_rate, tp_rate, thresholds = sklearn.metrics.roc_curve( 24 y_true, y_pred, pos_label=positive_label) 25 return sklearn.metrics.auc(fp_rate, tp_rate)
191 def plot_roc_auc_per_class(self): 192 """ 193 Plot the ROC AUC per class as a barplot. 194 """ 195 self.per_class_metrics_list[0] = sorted(self.per_class_metrics_list[0], key=lambda x: -float(x['ROC_auc'])) 196 fig, ax = plt.subplots() 197 198 ax.bar(x=list(range(len(self.per_class_metrics_list[0]))), 199 height=[float(x['ROC_auc']) for x in self.per_class_metrics_list[0]], 200 width=1, 201 color=colors['blue'], 202 alpha=0.7 203 ) 204 ax.set_ylabel('ROC AUC') 205 ax.set_xlabel('Class') 206 ax.set_title('ROC per Class') 207 plt.savefig(os.path.join(self.plot_path, 'roc_auc_per_class_{}{}.png'.format(self.step, self.early))) 208 plt.close()