Skip to content

Instantly share code, notes, and snippets.

@hvy
Created July 15, 2020 10:14
Show Gist options
  • Save hvy/9757f91ca49b6dbf97e4cb01fd6659a4 to your computer and use it in GitHub Desktop.
Save hvy/9757f91ca49b6dbf97e4cb01fd6659a4 to your computer and use it in GitHub Desktop.
import optuna
def objective(trial):
x = trial.suggest_int("x", 0, 2)
y = trial.suggest_float("y", -1.0, 1.0)
z = trial.suggest_float("z", 0.0, 1.5)
return x ** 2 + y ** 3 - z ** 4
study = optuna.create_study(sampler=optuna.samplers.RandomSampler())
study.optimize(objective, n_trials=100)
# Compute importances.
evaluator = optuna.importance.FanovaImportanceEvaluator()
importances = optuna.importance.get_param_importances(study, evaluator=evaluator)
for param_name, importance in importances.items():
# x: 0.5604609292882394
# z: 0.4170708373363104
# y: 0.022468233375450276
print("{}: {}".format(param_name, importance))
# Plot importances.
fig = optuna.visualization.plot_param_importances(study, evaluator=evaluator)
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment