Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions sklearn/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def auc_score(y_true, y_score):
return roc_auc_score(y_true, y_score)


def roc_auc_score(y_true, y_score):
def roc_auc_score(y_true, y_score, pos_label=None):
"""Compute Area Under the Curve (AUC) from prediction scores

Note: this implementation is restricted to the binary classification task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes since this pr is waiting to be merged #2460

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjoly How does #2460 will handle binary case? Will it still return one value for "positive" class or return ROC for both classes (i.e. no need in pos_label in this case)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does #2460 will handle binary case?

As it is at the moment, I haven't change the logic around the positive label handling.

Will it still return one value for "positive" class or return ROC for both classes (i.e. no need in pos_label in this case)?

It detects if y_true and y_score are in multilabel-indicator format. In that case, there isn't any ambiguity on the number of classes/labels. The format checking can be easily done by checking the number of dimension of y_true/y_score. Note taht It doesn't handle the problematic multiclass task.

Depending on the chosen averaging option, you will get one value for all binary tasks or one for each task.

Expand All @@ -374,12 +374,16 @@ def roc_auc_score(y_true, y_score):
----------

y_true : array, shape = [n_samples]
True binary labels.
True binary labels in range {0, 1} or {-1, 1}. If labels are not
binary, pos_label should be explicitly given.

y_score : array, shape = [n_samples]
Target scores, can either be probability estimates of the positive
class, confidence values, or binary decisions.

pos_label : int
Label considered as positive and others are considered negative.

Returns
-------
auc : float
Expand All @@ -403,11 +407,14 @@ def roc_auc_score(y_true, y_score):
>>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> roc_auc_score(y_true, y_scores)
0.75
>>> y_true = np.array(['No', 'No', 'Yes', 'Yes'])
>>> roc_auc_score(y_true, y_scores, pos_label='Yes')
0.75

"""
if len(np.unique(y_true)) != 2:
raise ValueError("AUC is defined for binary classification only")
fpr, tpr, tresholds = roc_curve(y_true, y_score)
fpr, tpr, tresholds = roc_curve(y_true, y_score, pos_label=pos_label)
return auc(fpr, tpr, reorder=True)


Expand Down