Skip to content

Fix importance computation for single-distributed params - #6500

Merged
c-bata merged 2 commits into
optuna:masterfrom
y0z:feature/fix-ped-anova-all-single
Mar 25, 2026
Merged

c-bata merged 2 commits into
optuna:masterfrom
y0z:feature/fix-ped-anova-all-single

Conversation

@y0z

@y0z y0z commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

Motivation & Description of the changes

Optuna's importance evaluators behave inconsistently when a parameter's distribution is single.

  • fANOVA and PED-ANOVA return {} if all parameters are single-distributed. On the other hand, MeanDecreaseImpurity returns the importance of all parameters as 0.0.

  • PED-ANOVA returns 0.0 for single-distributed parameters if any parameters are not single-distributed (this behavior is inconsistent with the case where all parameters are single-distributed, cf. L239 and L265).

  • Currently, those behaviors are undocumented and solely implementation-dependent. However, if a variable can only take on certain values, the importance can trivially be defined as 0.0 rather than undefined.

This PR changes the evaluators to return some importance for all parameters (especially, 0.0 if single-distributed). This ensures that access to param_importance[single_param_name] is always valid.

@y0z y0z added the optuna.importance Related to the `optuna.importance` submodule. This is automatically labeled by github-actions. label Mar 9, 2026
@y0z y0z changed the title Fix importance computation when all params are single. [WIP] Fix importance computation when all params are single. Mar 10, 2026
@y0z y0z changed the title [WIP] Fix importance computation when all params are single. Fix importance computation for single-distributed params Mar 10, 2026
@y0z y0z added the compatibility Change that breaks compatibility. label Mar 10, 2026
@c-bata c-bata self-assigned this Mar 11, 2026

@c-bata c-bata left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your pull request. I have two concerns regarding this change:

  1. The documentation for get_param_importances() function states that "the sum of the importance values are normalized to 1.0." If all parameters return 0.0, this rule will be violated. Do we need to update the documentation?
  2. Currently, Optuna Dashboard handles an empty importance dict by assigning 1 / len(search_space) to each parameter to ensure the sum equals 1. So that this PR changes the current behavior of Optuna Dashboard as well.

What do you think?

@y0z

y0z commented Mar 17, 2026 •

Copy link
Copy Markdown
Member Author

Thank you for your comment.

Based on my understanding, neither point 1 nor point 2 is problematic.

  • Regarding point 1, now, res contains all the params, including single-distributed ones. Then, if all params are single-distributed, we obtain dict((param, 1.0 / n_params) for param in res.keys()), whereas if non-single-distributed params exist, we obtain positive importance for them and zero importance for remaining single-distributed params. For both cases, the values are normalized by default since the normalize argument of get_param_importances is set to True by default. The only difference from the existing implementation is that it returns a dict of zeros instead of an empty dict when normalize is explicitly set to False by users and all parameters are single-distributed.

res = evaluator.evaluate(study, params=params, target=target)
if normalize:
s = sum(res.values())
if s == 0.0:
n_params = len(res)
return dict((param, 1.0 / n_params) for param in res.keys())
else:
return dict((param, value / s) for (param, value) in res.items())
else:
warn_experimental_argument("normalize")
return res

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Mar 24, 2026

@c-bata c-bata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@c-bata c-bata removed the stale Exempt from stale bot labeling. label Mar 25, 2026
@c-bata c-bata added this to the v4.9.0 milestone Mar 25, 2026
@c-bata
c-bata merged commit 73ed833 into optuna:master Mar 25, 2026
12 checks passed
@y0z
y0z deleted the feature/fix-ped-anova-all-single branch March 25, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility Change that breaks compatibility. optuna.importance Related to the `optuna.importance` submodule. This is automatically labeled by github-actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants