注意
前往末尾 下载完整的示例代码。
plot_param_importances
- optuna.visualization.matplotlib.plot_param_importances(study, evaluator=None, params=None, *, target=None, target_name='Objective Value')[源代码]
使用 Matplotlib 绘制超参数重要性图。
另请参阅
- 参数:
study (Study) – 一个优化过的 study。
evaluator (BaseImportanceEvaluator | None) – 一个重要性评估器对象,用于指定基于哪个算法进行重要性评估。默认为
FanovaImportanceEvaluator。params (list[str] | None) – 要评估的参数名称列表。如果为
None,则评估所有在所有已完成的 trial 中存在的参数。target (Callable[[FrozenTrial], float] | None) –
一个用于指定要显示的值的函数。如果为
None且study被用于单目标优化,则绘制目标值。对于多目标优化,如果target为None,则将绘制所有目标。注意
如果
study被用于多目标优化,此参数可用于指定要绘制哪个目标。例如,要仅获取第一个目标的超参数重要性,请使用target=lambda t: t.values[0]作为目标参数。target_name (str) – 要显示在轴标签上的目标的名称。如果
target为None,则将使用通过set_metric_names()设置的名称,这将覆盖此参数。
- 返回:
一个
matplotlib.axes.Axes对象。- 返回类型:
注意
于 v2.2.0 添加为实验性功能。接口可能在未来版本中更改,恕不另行通知。请参阅 https://github.com/optuna/optuna/releases/tag/v2.2.0。
以下代码片段展示了如何绘制超参数重要性。

/home/docs/checkouts/readthedocs.org/user_builds/optuna/checkouts/stable/docs/visualization_matplotlib_examples/optuna.visualization.matplotlib.param_importances.py:26: ExperimentalWarning:
optuna.visualization.matplotlib._param_importances.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 分钟 0.816 秒)