Skip to content

Add title to DecisionBoundaryDisplay #31558

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ansamz
Copy link
Contributor

@ansamz ansamz commented Jun 16, 2025

Hello,

Reference Issues/PRs

#27462 (partially)

What does this implement/fix? Explain your changes.

I tackled this part of StefanieSenger's request
add a title to the plot that clearly states which response_method from which estimator was used in the plot
what I did was save the response method and estimator in a variable in order to add them to the plot
and then using the set_title() mthod from matplotlib we can add the title to the plots.

Any other comments?

This is how I tested it on the iris dataset (not sure if this is the best approach to solving the issue)

disp_proba = DecisionBoundaryDisplay.from_estimator(
    classifier,
    X,
    response_method="predict_proba",
    xlabel=iris.feature_names[0],
    ylabel=iris.feature_names[1],
    alpha=0.5,
)
disp_proba.ax_.scatter(X[:, 0], X[:, 1], c=y, edgecolor="k", s=20)
title_proba = (
    f"Boundary: {disp_proba.estimator_name_}\n"
    f"Method: '{disp_proba.response_method_used_}'"
)
disp_proba.ax_.set_title(title_proba)
plt.show()

@betatim @glemaitre

Copy link

github-actions bot commented Jun 16, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: c27c2dc. Link to the linter CI: here

@betatim
Copy link
Member

betatim commented Jun 17, 2025

Thanks for making this PR and starting to tackle the issue!

What do you think about using the newly stored attributes in DecisionBoundaryDisplay.plot to set a title for the figure that it produces? That way people benefit "for free" from this and get a nicer plot without having to do anything

@ansamz
Copy link
Contributor Author

ansamz commented Jun 21, 2025

First apologies for the late reply, had a hectic week, please let me know if you find this way better. attached an example of how it would look like.
Figure_1

@betatim betatim requested review from lucyleeow and glemaitre June 26, 2025 11:27
@lucyleeow lucyleeow changed the title Adding more functionality to DecisionBoundaryDisplay #27462 Add title to DecisionBoundaryDisplay Jun 27, 2025
Copy link
Member

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ansamz !

Here are some thoughts. Also I wonder if the title could be something like:

'DecisionTreeClassifier ("predict" method)' or
'DecisionTreeClassifier using "predict" method'
?

Comment on lines 254 to 258
if estimator_name_to_display or response_method_to_display:
ax.set_title(
f"Boundary: {estimator_name_to_display} "
f"Method: {response_method_to_display}"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this logic. Do we want to add a title if only response_method_to_display is provided?
If we did, we'd have to change the title to e.g., 'Method: predict', or '"predict" method'

@lucyleeow
Copy link
Member

Also CI is failing, as you need to include the extra parameters in the class docstring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants