Repository navigation
FIX Add class-specific contour lines in DecisionBoundaryDisplay for predict_proba and decision_function - #33471
Conversation
| for idx, quad in enumerate(disp.surface_): | ||
| assert quad.cmap == cmaps[idx] | ||
| else: | ||
| assert_allclose(disp.surface_.colors, colors) |
There was a problem hiding this comment.
This used to be for the contour case, which is now handled by the changes above.
| mpl, self.multiclass_colors, self.n_classes | ||
| ) | ||
|
|
||
| if self.response.ndim == 2: # predict |
There was a problem hiding this comment.
This part moved down to line 385
| kwargs["antialiased"] = True | ||
|
|
||
| # predict_proba and decision_function differ for plotting methods | ||
| elif plot_method == "contour": |
There was a problem hiding this comment.
This part is now in line 370
|
@snath-xoc: You can find the code to play around with the contour lines in the PR description above. |
|
Also pinging @antoinebaker, if you have time :) |
There was a problem hiding this comment.
Thanks for the PR @AnneBeyer, on the provided example it looks great! A few formatting nitpicks, but LGTM.
Could you maybe launch the CI with the [doc build] commit message
https://scikit-learn.org/dev/developers/contributing.html#commit-message-markers
so that we can visually check some examples ?
| - :class:`inspection.DecisionBoundaryDisplay` with ``plot_method="contour"`` now also | ||
| displays class-specific contours for ``response_method="predict_proba"`` and | ||
| ``response_method="decision_function"``. | ||
| Class boundary contour lines are now displayed in black by default for all response | ||
| methods to avoid confusion. | ||
| By :user:`Anne Beyer <AnneBeyer>`. |
There was a problem hiding this comment.
The lines look uneven, we should rewrap the text. If you are using vscode, you can use the extension https://marketplace.visualstudio.com/items?itemName=stkb.rewrap
There was a problem hiding this comment.
(And same comment for some docstrings, the lines look uneven).
There was a problem hiding this comment.
I added the line break on purpose here, because there are two separate things: the intra-class contour lines (that were not displayed before) and changing the color to black for the inter-class contour lines.
There was a problem hiding this comment.
Usually (based on the changelogs I've looked at), the changelog is written as one block even if there are separate things done. (Unless these things are very different for example a fix and an API change or affecting different estimators in different ways, then each deserves its own changelog). So in this case I wouldn't put the line break.
Anyway it is really a nitpick :)
There was a problem hiding this comment.
the changelog is written as one block
Not sure, but maybe this is because of the bullet list format? Note that towncrier cannot handle >1 bullet point, but it can handle 1 bullet point with several sub-bullet points below. (just FYI)
|
Thank you for the feedback @antoinebaker! |
antoinebaker
left a comment
There was a problem hiding this comment.
Hi @AnneBeyer you have a few unrelated diff to the PR, otherwise the logic still looks good to me. Ping me when you need a final look /approval on the PR !
That list is super useful, thanks ! I'll take a look at the listed examples when doing the final review. |
|
I reverted setting
|
ogrisel
left a comment
There was a problem hiding this comment.
This looks like a net improvement. +1 for merge once the following simplification is addressed.
I think we could also want to make the binary case consistent with the rendering of the multiclass case by also adding a black line at predict_proba == 0.5 or decision_function == 0 but this can be done in a follow-up PR, and in particular after the refactoring in #33115 is completed.
lucyleeow
left a comment
There was a problem hiding this comment.
Mostly nits and test suggestions, otherwise LGTM!
Is it worth adding a test that instantiates the class and then classes plot ? AFAICT no tests currently do this, we always create an instance via from_estimator. I know we do not recommend use this way, but it is possible and may be worthwhile testing?
There are some cases where |
|
Getting the test for surface colour and |
|
Something for another clean-up PR: I noticed that some of the test check for |
lucyleeow
left a comment
There was a problem hiding this comment.
Just a nit, thank you for adding the extra test!
|
Thank you all, for all your feedback! |
|
Thanks for your work and patience @AnneBeyer ! |

Reference Issues/PRs
Closes #33108
What does this implement/fix? Explain your changes.
This PR adapts the behaviour when
plot_method="contour".The contour lines for each class are now also drawn when
response_method = predict_probaordecision_function.As discussed in #33108, I went for black lines for the class boundaries, as the boundary lines may overlap and the colors don't necessarily correspond to the classes.
For the same reason, I also changed the contour color for
response_method = predictto"black". Given that this display is mainly intended as an inspection tool,I only added a note on this in the docstring, without throwing a warning or giving other options to set the color.
One could think about making the class boundary contour dotted or even optional when
response_method = predict_probaordecision_function, but I'm not sure if it is worth spending too much time on possible refinements unless someone who is using them actually requests it?WDYT? @lucyleeow @ogrisel (also pinging @snath-xoc, in case you want to have a look)
This is what it looks like now:

Code
AI usage disclosure
I used AI assistance for:
Any other comments?
I also added
zorder=-1andantialiased=Trueas defaults (if not specified otherwise inkwargs)