备注
前往末尾 下载完整示例代码。
plot_param_importances
- optuna.visualization.plot_param_importances(study, evaluator=None, params=None, *, target=None, target_name='Objective Value')[源代码]
绘制超参数重要性。
参见
此函数可视化
optuna.importance.get_param_importances()的结果。- 参数:
study (Study) – 一个优化的研究。
evaluator (BaseImportanceEvaluator | None) – 一个重要性评估器对象,指定基于哪种算法进行重要性评估。默认为
FanovaImportanceEvaluator。 .. 注意::FanovaImportanceEvaluator在给定包含 1000+ 次试验的研究时,需要超过 1 分钟。我们发布了 optuna-fast-fanova 库, 这是一个 Cython 加速的 fANOVA 实现。 通过使用它,您可以在几秒钟内获得超参数的重要性。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 legend. Names set via
set_metric_names()will be used iftargetisNone, overriding this argument.
- 返回:
一个
plotly.graph_objects.Figure对象。- 返回类型:
Figure
以下代码片段展示了如何绘制超参数重要性。
import optuna
from plotly.io import show
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)
fig = optuna.visualization.plot_param_importances(study)
show(fig)
脚本总运行时间: (0 分钟 0.427 秒)