DOC Add examples to PrecisionRecall and ConfusionMatrix Display#17492
DOC Add examples to PrecisionRecall and ConfusionMatrix Display#17492thomasjpfan merged 7 commits intoscikit-learn:masterfrom
Conversation
|
cc @thomasjpfan |
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you for the PR @pardeep-singh !
|
|
||
| Examples | ||
| -------- | ||
| >>> import matplotlib.pyplot as plt |
There was a problem hiding this comment.
Some of our CI do not have matplotlib installed.
| >>> import matplotlib.pyplot as plt |
| >>> cm = confusion_matrix(y_test, predictions, labels=clf.classes_) | ||
| >>> disp = ConfusionMatrixDisplay(confusion_matrix=cm, | ||
| >>> display_labels=clf.classes_) | ||
| >>> disp.plot() |
There was a problem hiding this comment.
| >>> disp.plot() | |
| >>> disp.plot() # doctest: +SKIP |
|
|
||
| Examples | ||
| -------- | ||
| >>> import matplotlib.pyplot as plt |
There was a problem hiding this comment.
| >>> import matplotlib.pyplot as plt |
| >>> viz = PrecisionRecallDisplay(precision=precision, recall=recall) | ||
| >>> viz.plot() |
There was a problem hiding this comment.
| >>> viz = PrecisionRecallDisplay(precision=precision, recall=recall) | |
| >>> viz.plot() | |
| >>> disp = PrecisionRecallDisplay(precision=precision, recall=recall) | |
| >>> disp.plot() # doctest: +SKIP |
…into doc_add_metrics_examples
|
Hey @thomasjpfan , I have made the suggested changes. Can you please take a look at the latest commit? Thanks! |
| >>> X_train, X_test, y_train, y_test = train_test_split(X, | ||
| >>> y, | ||
| >>> random_state=0) |
There was a problem hiding this comment.
| >>> X_train, X_test, y_train, y_test = train_test_split(X, | |
| >>> y, | |
| >>> random_state=0) | |
| >>> X_train, X_test, y_train, y_test = train_test_split(X, y, | |
| ... random_state=0) |
| >>> X_train, X_test, y_train, y_test = train_test_split(X, | ||
| >>> y, | ||
| >>> random_state=0) |
There was a problem hiding this comment.
| >>> X_train, X_test, y_train, y_test = train_test_split(X, | |
| >>> y, | |
| >>> random_state=0) | |
| >>> X_train, X_test, y_train, y_test = train_test_split(X, y, | |
| ... random_state=0) |
|
Hey @thomasjpfan, I have made the latest suggested changes. Can you please check these? Also, I am not able to understand build failures. Can you please help me understand these? |
thomasjpfan
left a comment
There was a problem hiding this comment.
This should fix the failing tests.
You can run the docstring test locally by:
pytest sklearn/metrics/_plot/confusion_matrix.py| >>> 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) |
There was a problem hiding this comment.
| >>> random_state=0) | |
| ... random_state=0) |
| >>> predictions = clf.predict(X_test) | ||
| >>> cm = confusion_matrix(y_test, predictions, labels=clf.classes_) | ||
| >>> disp = ConfusionMatrixDisplay(confusion_matrix=cm, | ||
| >>> display_labels=clf.classes_) |
There was a problem hiding this comment.
| >>> display_labels=clf.classes_) | |
| ... display_labels=clf.classes_) |
| >>> 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) |
There was a problem hiding this comment.
| >>> random_state=0) | |
| ... random_state=0) |
|
@thomasjpfan Thanks, Verified by running the tests locally. I had to add the return value to |
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you @pardeep-singh !
LGTM
Reference Issues/PRs
References #3846
What does this implement/fix? Explain your changes.
This PR adds examples to PrecisionRecallDisplay and ConfusionMatrixDisplay classes.
Any other comments?
CC @violetr #dataumbrella