Evaluate ranking of positive-class scores
Binary classification
Scikit-Learn · Function
Computes the area under the receiver operating characteristic curve from prediction scores. It supports binary, multiclass, and multilabel classification, with restrictions determined by the input type and options.
The function compares true labels with prediction scores and integrates the resulting receiver-operating-characteristic curve. It supports binary, multiclass, and multilabel targets, with options controlling averaging, partial-AUC range, sample weighting, and multiclass handling.
sklearn.metrics.roc_auc_score(y_true, y_score, *, average='macro', sample_weight=None, max_fpr=None, multi_class='raise', labels=None)| Name | Type | Description |
|---|---|---|
y_true | array-like | True binary labels or binary label indicators; shape (n_samples,) or (n_samples, n_classes). |
y_score | array-like | Prediction scores; shape depends on the target type and may contain probabilities, confidence values, or decision values. |
average | {'micro', 'macro', 'samples', 'weighted'} or None, default='macro' | Averaging method; the default is 'macro'. |
sample_weight | array-like, default=None | Sample weights. |
max_fpr | float, default=None | Maximum false-positive rate for a standardized partial AUC; default is None. |
multi_class | {'raise', 'ovr', 'ovo'}, default='raise' | Multiclass strategy; default is 'raise'. |
labels | array-like, default=None | Explicit class-label ordering. |
float or ndarray of shape (n_classes,), depending on the averaging and target configuration.
from sklearn.metrics import roc_auc_score
labels = [0, 0, 1, 1]
scores = [0.1, 0.4, 0.35, 0.8]
print(roc_auc_score(labels, scores))Computes ROC AUC from binary labels and positive-class scores.
Binary classification
Multiclass classification
Multilabel classification
Imbalanced labels
It computes the area under the receiver operating characteristic curve from prediction scores. The documentation states that it handles binary, multiclass, and multilabel classification, subject to parameter restrictions.
Follow-up: How would you choose an averaging strategy? Use macro for an unweighted label mean, weighted to account for support, micro for global label-indicator accounting, or samples for per-instance averaging.
y_true contains the target labels or binary label indicators, while y_score contains probability estimates, confidence values, or non-thresholded decision values. For binary targets, y_score should contain the score for the class with the greater label.
Follow-up: Can hard class predictions replace scores? They can be passed as numeric values, but thresholded predictions discard ranking information and generally make ROC AUC less informative.
The average parameter controls aggregation for multilabel and multiclass-related calculations. The documented choices include micro, macro, weighted, and samples, while macro is the default.
Follow-up: What is the key distinction between macro and weighted? Macro uses an unweighted mean across labels; weighted uses each label's support.
roc_curveaucaverage_precision_scorelabel_ranking_average_precision_score