Skip to content
LearnPY
Matplotlibfunction reference

RocCurveDisplay

Plot a ROC curve directly from a fitted classifier.

Signature

RocCurveDisplay.from_estimator(estimator, X, y)

What it does

RocCurveDisplay.from_estimator scores the model, computes false and true positive rates, and plots the curve. from_predictions plots precomputed probabilities instead.

Parameters

estimatorestimator
A fitted classifier with predict_proba or decision_function.
Xarray-like
Feature matrix to score.
yarray-like
True binary labels.

Returns

RocCurveDisplay

Example

pythonRocCurveDisplay example
import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import RocCurveDisplay

model = LogisticRegression().fit(X_train, y_train)
RocCurveDisplay.from_estimator(model, X_test, y_test)
plt.show()

Watch out for

  • A curve computed on training data looks optimistic; plot the test fold.
  • ROC can look strong when positives are rare; read the precision-recall curve too.