备注
转到末尾 以下载完整示例代码。
plot_intermediate_values
- optuna.visualization.matplotlib.plot_intermediate_values(study)[源代码]
使用 Matplotlib 绘制研究中所有试验的中间值。
参见
备注
请参考 matplotlib.pyplot.legend 以调整生成的图例样式。
- 参数:
- 返回:
一个
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.intermediate_values.py:44: ExperimentalWarning:
plot_intermediate_values is experimental (supported from v2.2.0). The interface can change in the future.
<Axes: title={'center': 'Intermediate Values Plot'}, xlabel='Step', ylabel='Intermediate Value'>
import optuna
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)
optuna.visualization.matplotlib.plot_intermediate_values(study)
脚本总运行时间: (0 分钟 0.143 秒)