5 examples of 'roc curve sklearn' in Python

Every line of 'roc curve sklearn' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
499def test_roc(self):
500 self.lr_roc_curve(self.max_lr_f1(True))
109def 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()
302def get_roc_curve(model, data, thread_count=-1, plot=False):
303 """
304 Build points of ROC curve.
305
306 Parameters
307 ----------
308 model : catboost.CatBoost
309 The trained model.
310
311 data : catboost.Pool or list of catboost.Pool
312 A set of samples to build ROC curve with.
313
314 thread_count : int (default=-1)
315 Number of threads to work with.
316 If -1, then the number of threads is set to the number of CPU cores.
317
318 plot : bool, optional (default=False)
319 If True, draw curve.
320
321 Returns
322 -------
323 curve points : tuple of three arrays (fpr, tpr, thresholds)
324 """
325 if type(data) == Pool:
326 data = [data]
327 if not isinstance(data, list):
328 raise CatBoostError('data must be a catboost.Pool or list of pools.')
329 for pool in data:
330 if not isinstance(pool, Pool):
331 raise CatBoostError('one of data pools is not catboost.Pool')
332
333 roc_curve = _get_roc_curve(model._object, data, thread_count)
334
335 if plot:
336 with _import_matplotlib() as plt:
337 _draw(plt, roc_curve[0], roc_curve[1], 'False Positive Rate', 'True Positive Rate', 'ROC Curve')
338
339 return roc_curve
21def ROC_plot(features,X_,y_, pred_,title):
22 fpr_, tpr_, thresholds = roc_curve(y_, pred_)
23 optimal_idx = np.argmax(tpr_ - fpr_)
24#https://stackoverflow.com/questions/28719067/roc-curve-and-cut-off-point-python
25 optimal_threshold = thresholds[optimal_idx]
26 auc_ = auc(fpr_, tpr_)
27 title = "{} auc=".format(title)
28 print("{} auc={} OT={:.4g}".format(title, auc_,optimal_threshold))
29 plt.plot(fpr_, tpr_, label="{}:{:.4g}".format(title, auc_))
30 plt.xlabel('False positive rate')
31 plt.ylabel('True positive rate')
32 plt.title('SMPLEs={} Features={} OT={:.4g}'.format(X_.shape[0],len(features),optimal_threshold))
33 plt.legend(loc='best')
34 plt.savefig("./_auc_[{}].jpg".format(features))
35 plt.show()
36 return auc_,optimal_threshold
220def precision_recall_curve(clf, x_test, y_test):
221 from sklearn.metrics import precision_recall_curve
222
223 for i in range(2):
224 y_probabilities = [x[i] for x in clf.predict_proba(x_test)]
225 precision, recall, thresholds = precision_recall_curve(y_test, y_probabilities)
226
227 plt.title('Precision Recall Curve')
228 plt.plot(recall, precision, 'b')
229
230 plt.show()

Related snippets