@@ -365,7 +365,7 @@ def auc_score(y_true, y_score):
365365 return roc_auc_score (y_true , y_score )
366366
367367
368- def roc_auc_score (y_true , y_score ):
368+ def roc_auc_score (y_true , y_score , pos_label = None ):
369369 """Compute Area Under the Curve (AUC) from prediction scores
370370
371371 Note: this implementation is restricted to the binary classification task.
@@ -374,12 +374,16 @@ def roc_auc_score(y_true, y_score):
374374 ----------
375375
376376 y_true : array, shape = [n_samples]
377- True binary labels.
377+ True binary labels in range {0, 1} or {-1, 1}. If labels are not
378+ binary, pos_label should be explicitly given.
378379
379380 y_score : array, shape = [n_samples]
380381 Target scores, can either be probability estimates of the positive
381382 class, confidence values, or binary decisions.
382383
384+ pos_label : int
385+ Label considered as positive and others are considered negative.
386+
383387 Returns
384388 -------
385389 auc : float
@@ -403,11 +407,14 @@ def roc_auc_score(y_true, y_score):
403407 >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])
404408 >>> roc_auc_score(y_true, y_scores)
405409 0.75
410+ >>> y_true = np.array(['No', 'No', 'Yes', 'Yes'])
411+ >>> roc_auc_score(y_true, y_scores, pos_label='Yes')
412+ 0.75
406413
407414 """
408415 if len (np .unique (y_true )) != 2 :
409416 raise ValueError ("AUC is defined for binary classification only" )
410- fpr , tpr , tresholds = roc_curve (y_true , y_score )
417+ fpr , tpr , tresholds = roc_curve (y_true , y_score , pos_label = pos_label )
411418 return auc (fpr , tpr , reorder = True )
412419
413420
0 commit comments