Skip to content

Commit

Permalink
DOC Add example for metrics.RocCurveDisplay (scikit-learn#15214)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinfurt authored and rth committed Oct 27, 2019
1 parent 0f157e9 commit 0b284ff
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sklearn/metrics/_plot/roc_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class RocCurveDisplay:
figure_ : matplotlib Figure
Figure containing the curve.
Examples
--------
>>> import matplotlib.pyplot as plt # doctest: +SKIP
>>> import numpy as np
>>> from sklearn import metrics
>>> y = np.array([0, 0, 1, 1])
>>> pred = np.array([0.1, 0.4, 0.35, 0.8])
>>> fpr, tpr, thresholds = metrics.roc_curve(y, pred)
>>> roc_auc = metrics.auc(fpr, tpr)
>>> display = metrics.RocCurveDisplay(fpr=fpr, tpr=tpr, roc_auc=roc_auc,\
estimator_name='example estimator')
>>> display.plot() # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
"""

def __init__(self, fpr, tpr, roc_auc, estimator_name):
Expand Down Expand Up @@ -138,6 +152,19 @@ def plot_roc_curve(estimator, X, y, pos_label=None, sample_weight=None,
-------
display : :class:`~sklearn.metrics.RocCurveDisplay`
Object that stores computed values.
Examples
--------
>>> import matplotlib.pyplot as plt # doctest: +SKIP
>>> from sklearn import datasets, metrics, model_selection, svm
>>> X, y = datasets.make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = model_selection.train_test_split(\
X, y, random_state=0)
>>> clf = svm.SVC(random_state=0)
>>> clf.fit(X_train, y_train)
SVC(random_state=0)
>>> metrics.plot_roc_curve(clf, X_test, y_test) # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
"""
check_matplotlib_support('plot_roc_curve')

Expand Down

0 comments on commit 0b284ff

Please sign in to comment.