Repository navigation
ENH: Add xlim/ylim parameters to DecisionBoundaryDisplay.from_estimator - #31693
ShauryaDusht wants to merge 14 commits into
Conversation
lucyleeow
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
Could you please add some tests and a whats new entry: https://github.com/scikit-learn/scikit-learn/blob/main/doc/whats_new/upcoming_changes/README.md
lucyleeow
left a comment
There was a problem hiding this comment.
Let's also specify in the docstring that eps is ignored if both xlim and ylim given. Could we also move the the new kwargs to underneath eps?
|
Thanks for the swift review. I will add these changes soon. |
|
Hi @lucyleeow |
lucyleeow
left a comment
There was a problem hiding this comment.
Please place your tests in the existing decision boundary test: sklearn/inspection/_plot/tests/test_boundary_decision_display.py.
You will be able to use the test data and fixtures, so you don't have to repeat.
Your test cases are probably too long and more than what is actually needed. If you are using LLMs to help you with tests, please note that they tend to produce verbose code and careful oversight and review by yourself is probably best.
Note also that we don't use test classes. I am happy to take another look after you've carefully reviewed your tests. Thank you
…nto feature/decision-boundary-xlim-ylim
|
I’ve moved the tests to Also removed test classes and refactored the cases to be more generalized Thank you |
|
I tried it with the example code from the docs and noted the following:
I guess the problem is that the data is truncated accordingly in |
|
|
||
| if ax is None: | ||
| _, ax = plt.subplots() | ||
|
|
There was a problem hiding this comment.
| ax.set_xlim((self.xx0.min(), self.xx0.max())) | |
| ax.set_ylim((self.xx1.min(), self.xx1.max())) |
to explicitly set the limits for the axes
@AnneBeyer, I don't have much of the context without spending a few hours (which I can only do next week), but intuitively when setting xlim and ylim I would too expect the whole plot being limited to that subset. What about in addition to setting xlim and ylim on the plot, we clip the data (for instance using |
| f"`{name}` must be a tuple of (min, max) with min < max" | ||
| ) | ||
|
|
||
| x0, x1 = _safe_indexing(X, 0, axis=1), _safe_indexing(X, 1, axis=1) |
There was a problem hiding this comment.
I think this should be moved into the respective else statements below, as this is not needed if xlim and ylim are given.
@StefanieSenger I don't think this is useful here because the decision boundaries will extend beyond the data. In the case above, the scatter plot is only re-using the axes from the display object, so I don't think we have control over the data there, but setting the limits explicitly in the |
I would agree, let's zoom in on everything. As far as I remember the use case was looking at what the decision boundary looked like, outside of the training data limits (i.e. if
Weird! We seem to specify colors so maybe this is a matplotlib behaviour? I think it is worth investigating. |
|
Interestingly, the problem with the limits not limiting the whole plot, only the boundaries (described here #31693 (comment)), doesn't occur to me (using python: 3.12.2 and matplotlib: 3.9.2)... |
|
@StefanieSenger I created an environment with python: 3.12.2 and matplotlib: 3.9.2, but when I check out the code from this PR, I still get the same result as above. Only when I apply this fix, the axes are clipped accordingly. |
In the case of "predict", we actually don't specify any colors, which might be related to the problem here (I'll look into that next). When using "predict_proba", we do select colors, and the problem with the grey background is no longer there, but when plotting on top, this leads to a color inconsistency: |
|
I think I narrowed down the problem a bit more: |
|
On a related note (that I came across again while looking at #32867): There is a detailed handling of colors using the I was wondering if this is a bug or a design decision. Could you give me some feedback on this @lucyleeow? |
AFAICT this is done by doing a separate |
|
I think it's good if there is an easy way for the user to pass the same color map to |
|
Since @ShauryaDusht does not seem interested to finalize this PR, @AnneBeyer feel free to take over this work (once #33015 has been finalized). |
Currently, the colors are only saved as a class variable in the multiclass case. But we already discussed here that colors should be handled similarly in the binary/multiclass cases, so this will be addressed once we tackle point 4 from that discussion. |




Reference Issues/PRs
Towards #27462
What does this implement/fix? Explain your changes.
This PR adds
xlimandylimparameters toDecisionBoundaryDisplay.from_estimator()to allow users to override the automatic data-based plot limits.xlim=Noneandylim=Noneparameters to method signature