Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

roc_auc_score

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.

How it works

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.

Syntax

sklearn.metrics.roc_auc_score(y_true, y_score, *, average='macro', sample_weight=None, max_fpr=None, multi_class='raise', labels=None)

Parameters

NameTypeDescription
y_truearray-likeTrue binary labels or binary label indicators; shape (n_samples,) or (n_samples, n_classes).
y_scorearray-likePrediction 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_weightarray-like, default=NoneSample weights.
max_fprfloat, default=NoneMaximum false-positive rate for a standardized partial AUC; default is None.
multi_class{'raise', 'ovr', 'ovo'}, default='raise'Multiclass strategy; default is 'raise'.
labelsarray-like, default=NoneExplicit class-label ordering.

Returns

float or ndarray of shape (n_classes,), depending on the averaging and target configuration.

Key points

  • Use it to evaluate how well prediction scores rank positive examples ahead of negative examples.
  • The function supports binary, multiclass, and multilabel classification, subject to restrictions documented for individual parameters.
  • Scores may be probabilities, confidence values, or non-thresholded decision outputs rather than only calibrated probabilities.
  • With macro averaging, calculate each label's metric and then take their unweighted mean.
  • Weighted averaging gives labels with more true instances greater influence.

Common mistakes

  • Binary, multiclass, and multilabel inputs are supported, but their accepted score shapes and options differ.
  • For binary classification, pass the score for the class with the greater label, typically the positive class.
  • Macro averaging gives each label equal weight, so it does not adjust for class imbalance.

Example: Binary ROC AUC

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.

When to use it

Evaluate ranking of positive-class scores

Binary classification

Aggregate one-vs-rest or one-vs-one class discrimination

Multiclass classification

Summarize label-wise ranking performance

Multilabel classification

Compare macro and support-weighted aggregation

Imbalanced labels

Interview questions

QWhat does roc_auc_score measure?

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.

QWhat should y_score contain?

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.

QHow does average affect the result?

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_curve
  • auc
  • average_precision_score
  • label_ranking_average_precision_score

Source: roc_auc_score — scikit-learn 1.9.1 documentation. Checked 2026-10-15.