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
Fix format of values in confusion matrix plot. #16159
Merged
Merged
Changes from 104 commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
f3ee74f
"Changes to the values_format for plotting the confusion_matrix. This
5fb226b
"Fixes for confusion_matrix values_format."
cb0083e
"<= value for 0"
551efa8
"Changed back to == 0"
e253373
"Import math log10 for linting error"
02995c5
"Linting and hard-coded value checks now working"
e8019fb
"Use log(10) instead of 1e7 (python version error?)"
8d6f8a3
"If cmd.type == f test included"
3b28b17
"Added type test in the correct place"
6208f85
"Different IF statement, see if it fixes azure pipeline errors"
c32cc01
"Changed order and use np.log10 ofcourse"
18137c1
"Removed brackets"
409c251
"Added testing in test_plot_confusion_matrix (values_format)"
3e7168e
"Wrong value format"
23b3a20
"Changed the test_plot_confusion_matrix."
d31518a
"Add test plot confusion matrix"
5e9b925
"Added extra test cases for test_plot_confusion_matrix"
46fef3d
"Fixed testing values"
0c9cb36
"Added argument to the test function, duh"
d21a7ff
"New tests to also test if for values > 1e7"
93cdb7a
"New test version, made sure the values are now loaded into the model
af47489
"Improved test file"
c404c77
"New changes"
1f766ca
"Fixed the ConfusionMatrixDisplay class, where values where not
690736f
"Fixing of loop and test"
89e6d1a
"Changed if statement in the for loop and new test function"
ff0cd1a
"Changes to test function and added the if condition in the for-loop
745725e
"Removed the assert equal size statement."
7b007d3
"Forgot to add the improved ConfusionMatrixDisplay"
bbd9037
"Cleaned test file and now all inside the for-loop."
0baf844
"Declare variable before the if-statement check"
f672d22
"Made the if-statement cleaner."
4b791c0
"Updated test file, and added the statement where if the length of the
f01baf6
"Changed back to values larger than 1e7"
f8ab0ff
"Test if the failed tests on azure pipelines are because of my edits?"
8c11333
"Improved test file, and included expected values from the test."
c72ec0f
"Improved test of formats (explicitly check strings)"
0cf3a7a
"Modified the test function for test_plot_confusion_matrix"
f419191
"Improved test file, now check for literal string array equal."
a94ae2a
"Use ravel instead of flatten"
e5925b4
"Removed array and used list only with bare assert statement."
651b4c6
"Cleaned up the test file, no parameterize and cleaner code using
d4b28ff
"Added pyplot to the function parameter so it passes tests."
dd5875f
"Use values_format in parameter test, to see if it resolves
f100cb6
"Shorten the test file, rename of some variables, list comprehension"
0b3e021
"Changed to 1e6"
bc51fd3
"Now picks the shortest length format."
ae40567
"Small changes in confusion plot values"
960b96e
Merge branch 'confusion_fix'
a3d7470
"Changes to the values_format for plotting the confusion_matrix. This
db163e2
"Fixes for confusion_matrix values_format."
8029558
"<= value for 0"
1158bc9
"Changed back to == 0"
ccf94db
"Import math log10 for linting error"
44bc54d
"Linting and hard-coded value checks now working"
3896c9c
"Use log(10) instead of 1e7 (python version error?)"
0cc1ce0
"If cmd.type == f test included"
941ff90
"Added type test in the correct place"
553d550
"Different IF statement, see if it fixes azure pipeline errors"
bf74685
"Changed order and use np.log10 ofcourse"
a92f36b
"Removed brackets"
8f3aae7
"Added testing in test_plot_confusion_matrix (values_format)"
c9fe195
"Wrong value format"
868b99e
"Changed the test_plot_confusion_matrix."
255992c
"Add test plot confusion matrix"
69e0068
"Added extra test cases for test_plot_confusion_matrix"
177df61
"Fixed testing values"
594efe0
"Added argument to the test function, duh"
5f250fe
"New tests to also test if for values > 1e7"
2cc9ef3
"New test version, made sure the values are now loaded into the model
d0de1f3
"Improved test file"
1c6244c
"New changes"
81054c2
"Fixed the ConfusionMatrixDisplay class, where values where not
2106a4d
"Fixing of loop and test"
37abea4
"Changed if statement in the for loop and new test function"
3ec1ffa
"Changes to test function and added the if condition in the for-loop
e14c4a5
"Removed the assert equal size statement."
eb724db
"Forgot to add the improved ConfusionMatrixDisplay"
932a077
"Cleaned test file and now all inside the for-loop."
6029363
"Declare variable before the if-statement check"
67cf462
"Made the if-statement cleaner."
60253ea
"Updated test file, and added the statement where if the length of the
769a2f6
"Changed back to values larger than 1e7"
613cd80
"Test if the failed tests on azure pipelines are because of my edits?"
4531040
"Improved test file, and included expected values from the test."
52818d8
"Improved test of formats (explicitly check strings)"
32e64e8
"Modified the test function for test_plot_confusion_matrix"
3e60478
"Improved test file, now check for literal string array equal."
3aca5b4
"Use ravel instead of flatten"
2a857c8
"Removed array and used list only with bare assert statement."
f28914b
"Cleaned up the test file, no parameterize and cleaner code using
4465f5a
"Added pyplot to the function parameter so it passes tests."
c334548
"Use values_format in parameter test, to see if it resolves
dc35958
"Shorten the test file, rename of some variables, list comprehension"
080bb16
"Changed to 1e6"
7ac8e02
"Now picks the shortest length format."
d4ca82a
"Small changes in confusion plot values"
b80d38c
Merge branch 'confusion_fix' of https://github.com/Rick-Mackenbach/sc…
74f7244
"Fix of wrong merge"
a71357d
Merge branch 'confusion_fix' of https://github.com/Rick-Mackenbach/sc…
6c37b11
"Small change in test file"
19319e6
"Updated the logic for interpretability. Also small changes to test"
de4e76e
"Do the formatting of values in the if-statement, so shorter code :)"
666246d
"Changed test file to test for 'd' values"
7895260
"Added changes to the v0.23 what's news"
e920a7b
"Modified doc/whats_new/v0.23.rst"
3365587
Merge remote-tracking branch 'upstream/master' into pr/16159
thomasjpfan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ def plot(self, include_values=True, cmap='viridis', | |
|
||
values_format : str, default=None | ||
Format specification for values in confusion matrix. If `None`, | ||
the format specification is '.2g'. | ||
the format specification is 'd' or '.2g' whichever is shorter. | ||
|
||
ax : matplotlib axes, default=None | ||
Axes object to plot on. If `None`, a new figure and axes is | ||
|
@@ -83,22 +83,30 @@ def plot(self, include_values=True, cmap='viridis', | |
n_classes = cm.shape[0] | ||
self.im_ = ax.imshow(cm, interpolation='nearest', cmap=cmap) | ||
self.text_ = None | ||
|
||
cmap_min, cmap_max = self.im_.cmap(0), self.im_.cmap(256) | ||
|
||
if include_values: | ||
self.text_ = np.empty_like(cm, dtype=object) | ||
if values_format is None: | ||
values_format = '.2g' | ||
|
||
# print text with appropriate color depending on background | ||
thresh = (cm.max() + cm.min()) / 2.0 | ||
|
||
for i, j in product(range(n_classes), range(n_classes)): | ||
color = cmap_max if cm[i, j] < thresh else cmap_min | ||
self.text_[i, j] = ax.text(j, i, | ||
format(cm[i, j], values_format), | ||
ha="center", va="center", | ||
color=color) | ||
|
||
if values_format is None: | ||
text_cm = format(cm[i, j], '.2g') | ||
if cm.dtype.kind != 'f': | ||
text_d = format(cm[i, j], 'd') | ||
if len(text_d) < len(text_cm): | ||
text_cm = text_d | ||
else: | ||
text_cm = format(cm[i, j], values_format) | ||
|
||
self.text_[i, j] = ax.text( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I was not more clear. The current PR may call if values_format is None:
text_cm = format(cm[i, j], '.2g')
if cm.dtype.kind != 'f':
text_d = format(cm[i, j], 'd')
if len(text_d) < len(text_cm):
text_cm = text_d
else:
text_cm = format(cm[i, j], values_format)
self.text_[i, j] = ax.text(j, i, text_cm, ...) |
||
j, i, text_cm, | ||
ha="center", va="center", | ||
color=color) | ||
|
||
fig.colorbar(self.im_, ax=ax) | ||
ax.set(xticks=np.arange(n_classes), | ||
|
@@ -164,7 +172,7 @@ def plot_confusion_matrix(estimator, X, y_true, labels=None, | |
|
||
values_format : str, default=None | ||
Format specification for values in confusion matrix. If `None`, | ||
the format specification is '.2g'. | ||
the format specification is 'd' or '.2g' whichever is shorter. | ||
|
||
cmap : str or matplotlib Colormap, default='viridis' | ||
Colormap recognized by matplotlib. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think trying
.2g
and then tryingd
if applicable, is slightly clearerThis suggestion is to address #16159 (comment)
The test would need to updated to reflect this behavior.