Skip to content

ENH Improve ROC curves visualization and add option to plot chance level #25972

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

Closed
wants to merge 4 commits into from

Conversation

Charlie-XIAO
Copy link
Contributor

@Charlie-XIAO Charlie-XIAO commented Mar 24, 2023

Reference Issues/PRs

Fixes #25929.

What does this implement/fix? Explain your changes.

This implements the following visual improvements:

  • Set the limits of both x- and y-axis to [0, 1].
  • Change the plotting frame into loosely dotted lines so that the values near 0 or 1 can be seen clearly.
  • Fix aspect ratio to squared (i.e., y/x=1).
  • Add an option plot_chance_level to indicate whether to plot the chance level. This option is available via RocCurveDisplay.plot, RocCurveDisplay.from_estimator, and RocCurveDisplay.from_predictions.
  • Add an attribute chance_level_ to the RocCurveDisplay. If the chance level is plotted, the attribute would be the Matplotlib 2D line object of the chance level line. Otherwise, it would be None.

Any other comments?

I may have misunderstood what @glemaitre asked me to do in Issue #25929. If I'm doing wrong, please tell me and I will close this issue and open new ones ASAP.

Also, I'm aware that reviewers may not have permission to directly modify this PR, because I'm making this PR from my course repo according to the course policy. However, I will make changes ASAP when the reviewer makes a comment. Sorry for the inconvenience I may have caused you.

@Charlie-XIAO Charlie-XIAO changed the title ENH Improve ROC curves visualization quality ENH Improve ROC curves visualization and add option to plot chance level Mar 25, 2023
@glemaitre glemaitre self-requested a review March 27, 2023 13:35
@glemaitre
Copy link
Member

glemaitre commented Mar 27, 2023

Also, I'm aware that reviewers may not have permission to directly modify this PR

This is sometimes an annoying option on our side when we only want to push or merge a very small suggestion at the end of the PR. I would suggest always allowing maintainers to push into your PR, at least in the scikit-learn project.

@Charlie-XIAO
Copy link
Contributor Author

@glemaitre Sorry about that, this is a known issue of Github that I cannot give that permission if I'm not pushing from my own account. If that's inconvenient, I will close this one and start a new one.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

For backward compatibility, we need to have plot_chance_level=False. Otherwise, we change the behaviour.

In addition of adding chance_level_kwargs, we need a new test to check that we alter the style of the chance_level_ line.

We also need to check the examples where RocCurveDisplay is used. We need to remove the part we were plotting the chance level by hand and instead use the new feature. You can have a look in the examples folder for the example that import the RocCurveDisplay.

Comment on lines +132 to +135
# Set limits of axes to [0, 1] and fix aspect ratio to squared
ax.set_xlim((0, 1))
ax.set_ylim((0, 1))
ax.set_aspect(1)
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this change in another PR. We will need an additional entry in the changelog since we are fixing/improving the rendering.

Copy link
Member

Choose a reason for hiding this comment

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

It should be shared with PR and ROC curve

Comment on lines +137 to +141
# Plot the frame in dotted line, so that the curve can be
# seen better when values are close to 0 or 1
for s in ["right", "left", "top", "bottom"]:
ax.spines[s].set_linestyle((0, (1, 5)))
ax.spines[s].set_linewidth(0.5)
Copy link
Member

Choose a reason for hiding this comment

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

Same here. We can postpone the despining. It could also be shared between different type of plots. And we should be able to control it via some keywords.

Comment on lines +225 to 226

**kwargs : dict
Copy link
Member

Choose a reason for hiding this comment

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

Also add the documnetation for chance_level_kwargs

@Charlie-XIAO
Copy link
Contributor Author

Okay, thanks for your review. I will make new PRs soon adopting these changes from my own account, so that you can make direct modifications. Again, sorry for the inconvenience I may have caused you.

@Charlie-XIAO
Copy link
Contributor Author

Please see #25987

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.

Visual improvements for ROC and precision-recall plots
2 participants