备注
转到末尾 以下载完整示例代码。
plot_pareto_front
- optuna.visualization.plot_pareto_front(study, *, target_names=None, include_dominated_trials=True, axis_order=None, constraints_func=None, targets=None)[源代码]
绘制研究中的帕累托前沿。
参见
请参考 使用 Optuna 进行多目标优化 以获取帕累托前沿可视化的教程。
- 参数:
study (Study) – A
Studyobject whose trials are plotted for their objective values. The number of objectives must be either 2 or 3 whentargetsisNone.target_names (list[str] | None) – Objective name list used as the axis titles. If
Noneis specified, “Objective {objective_index}” is used instead. Iftargetsis specified for a study that does not contain any completed trial,target_namemust be specified.include_dominated_trials (bool) – 一个标志,用于包含所有占优试验的目标值。
axis_order (list[int] | None) –
A list of indices indicating the axis order. If
Noneis specified, default order is used.axis_orderandtargetscannot be used at the same time.警告
在v3.0.0中已弃用。此功能将在未来被移除。该功能的移除目前计划在v5.0.0版本中进行,但此计划可能会更改。请参阅https://github.com/optuna/optuna/releases/tag/v3.0.0。
constraints_func (Callable[[FrozenTrial], Sequence[float]] | None) –
An optional function that computes the objective constraints. It must take a
FrozenTrialand return the constraints. The return value must be a sequence offloats. A value strictly larger than 0 means that a constraint is violated. A value equal to or smaller than 0 is considered feasible. This specification is the same as in, for example,NSGAIISampler.如果有,试验被分为三类:可行且最佳、可行但非最佳、不可行。类别以不同颜色显示。这里,一个试验是否为最佳(在帕累托前沿)是根据忽略所有不可行试验来确定的。
警告
在 v4.0.0 中已弃用。此功能将在未来被移除。该功能的移除目前计划在 v6.0.0 进行,但此计划可能会更改。参见 https://github.com/optuna/optuna/releases/tag/v4.0.0。
targets (Callable[[FrozenTrial], Sequence[float]] | None) – 返回要显示的目标值的函数。此函数的参数是
FrozenTrial。axis_order和targets不能同时使用。如果study.n_objectives既不是2也不是3,则必须指定targets。 .. 注意:: 在 v3.0.0 中作为实验性功能添加。接口可能会在较新的版本中发生变化,而无需事先通知。 请参阅 https://github.com/optuna/optuna/releases/tag/v3.0.0。
- 返回:
一个
plotly.graph_objects.Figure对象。- 返回类型:
Figure
以下代码片段展示了如何绘制一个研究的帕累托前沿。
import optuna
from plotly.io import show
def objective(trial):
x = trial.suggest_float("x", 0, 5)
y = trial.suggest_float("y", 0, 3)
v0 = 4 * x**2 + 4 * y**2
v1 = (x - 5) ** 2 + (y - 5) ** 2
return v0, v1
study = optuna.create_study(directions=["minimize", "minimize"])
study.optimize(objective, n_trials=50)
fig = optuna.visualization.plot_pareto_front(study)
show(fig)
以下代码片段展示了如何绘制一个三维研究的二维帕累托前沿。这个例子是可扩展的,例如,用于绘制一个四维研究的二维或三维帕累托前沿,等等。
import optuna
from plotly.io import show
def objective(trial):
x = trial.suggest_float("x", 0, 5)
y = trial.suggest_float("y", 0, 3)
v0 = 5 * x**2 + 3 * y**2
v1 = (x - 10) ** 2 + (y - 10) ** 2
v2 = x + y
return v0, v1, v2
study = optuna.create_study(directions=["minimize", "minimize", "minimize"])
study.optimize(objective, n_trials=100)
fig = optuna.visualization.plot_pareto_front(
study,
targets=lambda t: (t.values[0], t.values[1]),
target_names=["Objective 0", "Objective 1"],
)
show(fig)
脚本总运行时间: (0 分钟 0.178 秒)