备注
转到末尾 以下载完整示例代码。
plot_param_importances
- optuna.visualization.matplotlib.plot_param_importances(study, evaluator=None, params=None, *, target=None, target_name='Objective Value')[源代码]
使用 Matplotlib 绘制超参数重要性图表。
参见
- 参数:
study (Study) – 一个优化的研究。
evaluator (BaseImportanceEvaluator | None) – 一个重要性评估器对象,指定基于哪种算法进行重要性评估。默认为
FanovaImportanceEvaluator。params (list[str] | None) – A list of names of parameters to assess. If
None, all parameters that are present in all of the completed trials are assessed.target (Callable[[FrozenTrial], float] | None) –
A function to specify the value to display. If it is
Noneandstudyis being used for single-objective optimization, the objective values are plotted. For multi-objective optimization, all objectives will be plotted iftargetisNone.备注
此参数可用于指定在
study用于多目标优化时绘制哪个目标。例如,要仅获取第一个目标的超参数重要性,请为目标参数使用target=lambda t: t.values[0]。target_name (str) – Target’s name to display on the axis label. Names set via
set_metric_names()will be used iftargetisNone, overriding this argument.
- 返回:
一个
matplotlib.axes.Axes对象。- 返回类型:
备注
作为实验性功能在 v2.2.0 中添加。接口可能会在更新版本中未经事先通知而更改。请参阅 https://github.com/optuna/optuna/releases/tag/v2.2.0。
以下代码片段展示了如何绘制超参数重要性。

/Users/cw/baidu/code/fin_tool/github/optuna/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 分钟 0.417 秒)