-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
DOC Add examples to PrecisionRecall and ConfusionMatrix Display #17492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC Add examples to PrecisionRecall and ConfusionMatrix Display #17492
Conversation
cc @thomasjpfan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @pardeep-singh !
|
||
Examples | ||
-------- | ||
>>> import matplotlib.pyplot as plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> disp.plot() | |
>>> disp.plot() # doctest: +SKIP |
|
||
Examples | ||
-------- | ||
>>> import matplotlib.pyplot as plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> import matplotlib.pyplot as plt |
>>> viz = PrecisionRecallDisplay(precision=precision, recall=recall) | ||
>>> viz.plot() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> random_state=0) | |
... random_state=0) |
@thomasjpfan Thanks, Verified by running the tests locally. I had to add the return value to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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