-
-
Notifications
You must be signed in to change notification settings - Fork 26k
FIX: Regression in DecisionBoundaryDisplay.from_estimator with colors and plot_method='contour' #31553
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
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for the PR. A few observations:
- The places which are not tested (complaining codecov) need to be tested.
- The diff is hard to review, and it seems certain logic is removed from the new code, which should be there? Please comment on how things have changed and if any, why logic is removed.
"Cannot specify both 'cmap' and 'colors' in kwargs. " | ||
"Please use only one of them." |
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.
isn't one deprecated upstream? We should recommend the new way.
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.
Thanks for the suggestion!
To clarify: matplotlib hasn't deprecated either cmap or colors — both are still valid and serve different purposes.
That said, I agree it's better to recommend cmap as the preferred option, especially for continuous or gradient-based plots. I’ll update the error message accordingly to reflect that.
Thanks for the feedback! I understand that the diff is quite large and thus harder to review. After attempting to resolve the conflicts between And to clarify: matplotlib hasn't deprecated either cmap or colors — both are still valid and serve different purposes. That said, I agree it's better to recommend cmap as the preferred option, especially for continuous or gradient-based plots. Below is a breakdown of the changes for clarity: Original Logicif (
isinstance(self.multiclass_colors, str)
or self.multiclass_colors is None
):
...
if cmap == "tab10" and n_responses <= 10:
colors = ...
elif cmap == "tab20" and n_responses <= 20:
colors = ...
else:
colors = ...
elif isinstance(self.multiclass_colors, str):
colors = ...
else: # self.multiclass_colors is a list
colors = ...
Updated Logic (New Version):if self.multiclass_colors is None:
if "cmap" in kwargs and "colors" in kwargs:
raise ValueError(...)
if "cmap" in kwargs:
...
elif "colors" in kwargs:
...
else:
...
else:
if "cmap" in kwargs:
warnings.warn(...) # 'cmap' will be ignored
if "colors" in kwargs:
warnings.warn(...) # 'colors' will be ignored
if isinstance(self.multiclass_colors, str):
...
elif isinstance(self.multiclass_colors, list):
...
else:
raise ValueError(...) This new structure separates the logic into two clear branches:
This design avoids ambiguity, enforces correct usage, and adds necessary warnings and error handling. Contour-specific FixThe actual fix related to the contour plotting method is limited to lines 267 to 271, specifically in the following section: if plot_method == "contour":
# Plot only argmax map for contour
class_map = self.response.argmax(axis=2)
self.surface_ = plot_func(
self.xx0, self.xx1, class_map, colors=colors, **kwargs
) Regarding tests – I will add appropriate test cases to ensure the new logic is properly covered and behaves as expected in all scenarios. |
Reference Issues/PRs
Fixes: #31546
Summary
This PR addresses bugs introduced in PR #29797. It restores the previous behavior when plot_method='contour' is specified and improves the handling of
colors
,cmap
, andmulticlass_colors
arguments in DecisionBoundaryDisplay.from_estimator.Problem
Currently, passing the
colors
keyword argument toDecisionBoundaryDisplay.from_estimator
raises aValueError
, as bothcmap
andcolors
are set simultaneously. Additionally, when plot_method='contour' is used, the decision boundary is no longer displayed; instead, a surface plot of the class predictions is drawn, which deviates from the intended behavior.Solution
This PR introduces the following enhancements to clarify and handle these scenarios:
multiclass_colors
is None:colors
andcmap
are specified -> raise a ValueErrorcmap
is specified -> determine whether the colormap is continuous or discrete and convert it to RGBA accordinglycolors
is specified -> convert to RGBAcmap
norcolors
is specified -> use the default colormapmulticlass_colors
is not None:cmap
orcolors
is specified -> issue a warning and only usemulticlass_colors
multiclass_colors
is a string -> treat it as a colormap name and convert it to RGBA depending on whether it's continuous or discretemulticlass_colors
is a list -> convert it directly to RGBADecisionBoundaryDisplay
#29797 behavior)