plot_param_importances

optuna.visualization.matplotlib.plot_param_importances(study, evaluator=None, params=None, *, target=None, target_name='Objective Value')[source]

使用 Matplotlib 绘制超参数重要性。

另请参阅

请参阅 optuna.visualization.plot_param_importances() 以获取示例。

参数:
  • study (Study) – 一个已优化的 study 对象。

  • evaluator (BaseImportanceEvaluator | None) – 指定用于重要性评估算法的评估器对象。默认为 FanovaImportanceEvaluator

  • params (list[str] | None) – 需要评估的参数名称列表。如果为 None,则评估所有在所有已完成 trials 中都存在的参数。

  • target (Callable[[FrozenTrial], float] | None) –

    指定要显示的值的函数。如果为 Nonestudy 用于单目标优化,则绘制目标值。对于多目标优化,如果 targetNone,则会绘制所有目标。

    注意

    如果 study 用于多目标优化,此参数可用于指定要绘制的目标。例如,要仅获取第一个目标的超参数重要性,可以将 target 参数设置为 target=lambda t: t.values[0]

  • target_name (str) – 在坐标轴标签上显示的目标名称。如果 targetNone,则会使用通过 set_metric_names() 设置的名称,并覆盖此参数。

返回:

一个 matplotlib.axes.Axes 对象。

返回类型:

Axes

注意

在 v2.2.0 中添加为实验性功能。接口在后续版本中可能会更改,恕不另行通知。请参阅 https://github.com/optuna/optuna/releases/tag/v2.2.0

以下代码片段展示了如何绘制超参数重要性。

Hyperparameter Importances
/home/docs/checkouts/readthedocs.org/user_builds/optuna/checkouts/stable/docs/visualization_matplotlib_examples/optuna.visualization.matplotlib.param_importances.py:26: ExperimentalWarning:

plot_param_importances is experimental (supported from v2.2.0). The interface can change in the future.


<Axes: title={'left': 'Hyperparameter Importances'}, xlabel='Hyperparameter Importance', ylabel='Hyperparameter'>

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


sampler = optuna.samplers.RandomSampler(seed=10)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)

optuna.visualization.matplotlib.plot_param_importances(study)

脚本总运行时间: (0 minutes 0.856 seconds)

Sphinx-Gallery 生成的图库