Implementation:Scikit learn Scikit learn RocCurveDisplay
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Visualization |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for visualizing Receiver Operating Characteristic (ROC) curves provided by scikit-learn.
Description
The RocCurveDisplay class provides visualization of ROC curves, which plot the true positive rate against the false positive rate at various classification thresholds. It supports plotting single or multiple curves, displaying AUC scores in the legend, and optionally showing a chance-level diagonal line. The class supports creation from an estimator, from predictions, or from cross-validation results via from_cv_results. It accepts lists of arrays for plotting multiple curves simultaneously.
Usage
Use this display class when evaluating binary classifiers by visualizing their ROC curves, comparing multiple models or cross-validation folds, or presenting threshold-independent classification performance in publications and reports.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/metrics/_plot/roc_curve.py
Signature
class RocCurveDisplay(_BinaryClassifierCurveDisplayMixin):
def __init__(self, *, fpr, tpr, roc_auc=None, name=None, pos_label=None,
estimator_name=None)
def plot(self, ax=None, *, name=None, plot_chance_level=False,
chance_level_kw=None, despine=False, curve_kwargs=None, **kwargs)
@classmethod
def from_estimator(cls, estimator, X, y, *, sample_weight=None, drop_intermediate=True,
response_method="auto", pos_label=None, name=None, ax=None,
plot_chance_level=False, chance_level_kw=None, despine=False, **kwargs)
@classmethod
def from_predictions(cls, y_true, y_pred, *, sample_weight=None, drop_intermediate=True,
pos_label=None, name=None, ax=None, plot_chance_level=False,
chance_level_kw=None, despine=False, **kwargs)
@classmethod
def from_cv_results(cls, cv_results, X, y, *, sample_weight=None, drop_intermediate=True,
response_method="auto", pos_label=None, name=None, ax=None,
plot_chance_level=False, chance_level_kw=None, despine=False,
curve_kwargs=None, **kwargs)
Import
from sklearn.metrics import RocCurveDisplay
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| fpr | ndarray or list of ndarrays | Yes | False positive rate values (one per curve) |
| tpr | ndarray or list of ndarrays | Yes | True positive rate values (one per curve) |
| roc_auc | float or list of floats | No | Area under ROC curve for legend labeling |
| name | str or list of str | No | Name(s) for labeling legend entries |
| pos_label | int, float, bool or str | No | The label of the positive class |
| plot_chance_level | bool | No | Whether to plot the diagonal chance level line (default False) |
| despine | bool | No | Whether to remove top and right spines (default False) |
| drop_intermediate | bool | No | Whether to drop suboptimal thresholds (default True) |
| cv_results | dict | Yes (from_cv_results) | Cross-validation results from cross_validate |
Outputs
| Name | Type | Description |
|---|---|---|
| display | RocCurveDisplay | Display object with line_, chance_level_, ax_, and figure_ attributes |
Usage Examples
Basic Usage
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import RocCurveDisplay
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X, y = make_classification(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
clf = SVC(random_state=0).fit(X_train, y_train)
# Plot ROC curve from estimator
RocCurveDisplay.from_estimator(clf, X_test, y_test, plot_chance_level=True)
plt.show()
# Or from pre-computed values
from sklearn.metrics import roc_curve, auc
y_score = clf.decision_function(X_test)
fpr, tpr, _ = roc_curve(y_test, y_score)
roc_auc = auc(fpr, tpr)
display = RocCurveDisplay(fpr=fpr, tpr=tpr, roc_auc=roc_auc, name="SVC")
display.plot(plot_chance_level=True)
plt.show()