8000 DOC Add examples to PrecisionRecall and ConfusionMatrix Display (#17492) · viclafargue/scikit-learn@cce7763 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit cce7763

Browse files
pardeep-singhviclafargue
authored andcommitted
DOC Add examples to PrecisionRecall and ConfusionMatrix Display (scikit-learn#17492)
1 parent 1128c27 commit cce7763

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

sklearn/metrics/_plot/confusion_matrix.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ class ConfusionMatrixDisplay:
4040
4141
figure_ : matplotlib Figure
4242
Figure containing the confusion matrix.
43+
44+
Examples
45+
--------
46+
>>> from sklearn.datasets import make_classification
47+
>>> from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
48+
>>> from sklearn.model_selection import train_test_split
49+
>>> from sklearn.svm import SVC
50+
>>> X, y = make_classification(random_state=0)
51+
>>> X_train, X_test, y_train, y_test = train_test_split(X, y,
52+
... random_state=0)
53+
>>> clf = SVC(random_state=0)
54+
>>> clf.fit(X_train, y_train)
55+
SVC(random_state=0)
56+
>>> predictions = clf.predict(X_test)
57+
>>> cm = confusion_matrix(y_test, predictions, labels=clf.classes_)
58+
>>> disp = ConfusionMatrixDisplay(confusion_matrix=cm,
59+
... display_labels=clf.classes_)
60+
>>> disp.plot() # doctest: +SKIP
4361
"""
4462
def __init__(self, confusion_matrix, *, display_labels=None):
4563
self.confusion_matrix = confusion_matrix

sklearn/metrics/_plot/precision_recall_curve.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ class PrecisionRecallDisplay:
4040
4141
figure_ : matplotlib Figure
4242
Figure containing the curve.
43+
44+
Examples
45+
--------
46+
>>> from sklearn.datasets import make_classification
47+
>>> from sklearn.metrics import (precision_recall_curve,
48+
... PrecisionRecallDisplay)
49+
>>> from sklearn.model_selection import train_test_split
50+
>>> from sklearn.svm import SVC
51+
>>> X, y = make_classification(random_state=0)
52+
>>> X_train, X_test, y_train, y_test = train_test_split(X, y,
53+
... random_state=0)
54+
>>> clf = SVC(random_state=0)
55+
>>> clf.fit(X_train, y_train)
56+
SVC(random_state=0)
57+
>>> predictions = clf.predict(X_test)
58+
>>> precision, recall, _ = precision_recall_curve(y_test, predictions)
59+
>>> disp = PrecisionRecallDisplay(precision=precision, recall=recall)
60+
>>> disp.plot() # doctest: +SKIP
4361
"""
4462
def __init__(self, precision, recall, *,
4563
average_precision=None, estimator_name=None):

0 commit comments

Comments
 (0)
0