注意
跳到文末下载完整的示例代码。
plot_intermediate_values
- optuna.visualization.plot_intermediate_values(study)[source]
绘制研究中所有试验的中间值。
- 参数:
- 返回:
一个
plotly.graph_objects.Figure
对象。- 返回类型:
Figure
以下代码片段展示了如何绘制中间值。
import optuna
from plotly.io import show
def f(x):
return (x - 2) ** 2
def df(x):
return 2 * x - 4
def objective(trial):
lr = trial.suggest_float("lr", 1e-5, 1e-1, log=True)
x = 3
for step in range(128):
y = f(x)
trial.report(y, step=step)
if trial.should_prune():
raise optuna.TrialPruned()
gy = df(x)
x -= gy * lr
return y
sampler = optuna.samplers.TPESampler(seed=10)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=16)
fig = optuna.visualization.plot_intermediate_values(study)
show(fig)
脚本总运行时间: (0 分钟 0.302 秒)