Skip to content
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

Sorts categorical values on axis that contains only numerical values in visualization.matplotlib.plot_slice #2709

Merged
merged 3 commits into from
Jun 2, 2021

Conversation

Muktan
Copy link
Contributor

@Muktan Muktan commented May 29, 2021

Motivation

The slice plot's axis can be improved (by sorting) when a categorical distribution suggests only int or float values. #2605

Description of the changes

Now the y axis is sorted if it only contains numerical values.
Before:
image

After:
image

Also, if y contains mix of categorical and the numerical e.g. y = trial.suggest_categorical("y", [1,"2asd","3asd","asd"])
previous and current result remains same as follows:
image

Can be reviewed by: @nzw0301

@github-actions github-actions bot added the optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions. label May 29, 2021
Copy link
Member

@nzw0301 nzw0301 left a comment

Choose a reason for hiding this comment

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

@Muktan Thank you for your pull request! It looks great.

@codecov-commenter
Copy link

codecov-commenter commented May 30, 2021

Codecov Report

Merging #2709 (45ad715) into master (bfb41ab) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2709   +/-   ##
=======================================
  Coverage   91.66%   91.66%           
=======================================
  Files         140      140           
  Lines       11522    11522           
=======================================
  Hits        10562    10562           
  Misses        960      960           
Impacted Files Coverage Δ
optuna/visualization/matplotlib/_slice.py 94.79% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bfb41ab...45ad715. Read the comment docs.

@nzw0301
Copy link
Member

nzw0301 commented May 30, 2021

Sorry, I realised that we can make the conditions simpler.

How about replacing this part

    elif _is_numerical(trials, param):
        x_values = [x for x in x_values]
        scale = "numerical"
    elif _is_categorical(trials, param):
        x_values = [str(x) for x in x_values]
        scale = "categorical"

with as follows?:

    elif not _is_numerical(trials, param):
        x_values = [str(x) for x in x_values]
        scale = "categorical"

@Muktan
Copy link
Contributor Author

Muktan commented May 30, 2021

Okay, let me try these conditions and if everything is good will create another comit.

@Muktan Muktan requested a review from nzw0301 May 30, 2021 09:18
Copy link
Member

@nzw0301 nzw0301 left a comment

Choose a reason for hiding this comment

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

Thank you for your quick response. I have one minor comment.

optuna/visualization/matplotlib/_slice.py Outdated Show resolved Hide resolved
@Muktan Muktan requested a review from nzw0301 May 30, 2021 09:50
Copy link
Member

@nzw0301 nzw0301 left a comment

Choose a reason for hiding this comment

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

Awesome! Again, thank you for your quick update.

@Muktan
Copy link
Contributor Author

Muktan commented Jun 1, 2021

Hey @nzw0301!
This PR is not merged yet, so is there anything that needs to be done further?

@nzw0301
Copy link
Member

nzw0301 commented Jun 1, 2021

Hi @Muktan, the pull request needs two approvals from dev-members to be merged into the master branch. So please kindly give us time.

@Muktan
Copy link
Contributor Author

Muktan commented Jun 1, 2021

Ok got it, Thank You.

Copy link
Contributor

@Crissman Crissman left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for another!

@Crissman Crissman merged commit d4a286b into optuna:master Jun 2, 2021
@HideakiImamura HideakiImamura added the feature Change that does not break compatibility, but affects the public interfaces. label Jun 4, 2021
@HideakiImamura HideakiImamura added this to the v2.8.0 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Change that does not break compatibility, but affects the public interfaces. optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort categorical values on axis that contains only numerical values in visualization.matplotlib.plot_slice
5 participants