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

Scikit-Learn · Function

roc_curve

Computes the receiver operating characteristic for binary classification by evaluating scores at decision thresholds. Returns false-positive rates, true-positive rates, and the thresholds that produce them.

How it works

roc_curve evaluates a binary classifier across decision thresholds. It returns the false-positive rate and true-positive rate at each decreasing threshold, optionally using sample weights and omitting thresholds that would create collinear plotted points.

Syntax

sklearn.metrics.roc_curve(y_true, y_score, *, pos_label=None, sample_weight=None, drop_intermediate=True)

Parameters

NameTypeDescription
y_truearray-likeTrue binary labels, shape (n_samples).
y_scorearray-like of shape (n_samples)Scores for the positive class: probabilities, confidence values, or non-thresholded decision values.
pos_labelint, float, bool or str, default=NoneLabel of the positive class; inferred when labels are -1/1 or 0/1.
sample_weightarray-like of shape (n_samples,), default=NonePer-sample weights.
drop_intermediatebool, default=TrueWhether to omit thresholds whose points are collinear with neighboring ROC points.

Returns

A tuple containing fpr, tpr, and thresholds arrays: increasing false-positive rates, increasing true-positive rates, and decreasing decision thresholds.

Key points

  • Computes ROC coordinates for a binary classifier over score thresholds.
  • Each false-positive-rate entry counts predictions scoring at least the corresponding threshold.
  • The true-positive-rate output is ordered consistently with the increasing ROC operating points.
  • Thresholds are returned in decreasing order and determine the paired rate values.
  • drop_intermediate can remove redundant collinear points from the returned curve.

Common mistakes

  • Provide pos_label when the target labels use a convention other than -1/1 or 0/1.
  • This function does not directly support multiclass targets; use an appropriate multiclass strategy first.
  • When passing decision_function output, its sign must identify the positive class.

Example: Compute ROC coordinates

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve

X, y = make_classification(random_state=0)
model = LogisticRegression(max_iter=1000).fit(X, y)
fpr, tpr, thresholds = roc_curve(y, model.predict_proba(X)[:, 1])
print(fpr)
print(tpr)
print(thresholds)

Fits a binary classifier, supplies positive-class probabilities to roc_curve, and prints the false-positive rates, true-positive rates, and thresholds.

When to use it

Model discrimination analysis

Comparing binary classifiers by their ranking behavior across operating points.

Threshold selection

Choosing a threshold while examining the trade-off between false positives and true positives.

Weighted ROC analysis

Evaluating observations that contribute unequally to the metric.

Interview questions

QWhat does roc_curve return?

roc_curve returns three arrays: false-positive rates, true-positive rates, and the decision thresholds used to calculate them. The rates are ordered as thresholds decrease.

Follow-up: How would you reduce the number of plotted points? Set drop_intermediate=True, which removes thresholds whose ROC points are collinear with neighboring points.

QWhat should be passed as y_score?

y_score must be a continuous ranking or score for the positive class, such as a probability estimate or classifier confidence. It can also be a non-thresholded decision value.

Follow-up: What constraint applies to decision_function values? Values at least zero should represent the positive class.

QWhat classification task and label conventions does it support?

The function is limited to binary classification. If labels are not -1/1 or 0/1, explicitly identify the positive class with pos_label.

Follow-up: How can class imbalance in observations be reflected? Supply sample_weight with one weight per sample.

  • roc_auc_score
  • RocCurveDisplay
  • RocCurveDisplay.from_estimator
  • RocCurveDisplay.from_predictions

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