plot_intermediate_values

optuna.visualization.matplotlib.plot_intermediate_values(study)[source]

使用 Matplotlib 绘制 study 中所有 trials 的中间值。

另请参阅

有关示例,请参阅 optuna.visualization.plot_intermediate_values()

注意

请参阅 matplotlib.pyplot.legend 以调整生成的图例样式。

参数:

study (Study) – 一个 Study 对象,其 trials 的中间值将被绘制。

返回:

一个 matplotlib.axes.Axes 对象。

返回类型:

Axes

注意

作为实验性功能在 v2.2.0 中添加。接口在更新版本中可能会更改,恕不另行通知。请参阅 https://github.com/optuna/optuna/releases/tag/v2.2.0

以下代码片段展示了如何绘制中间值。

Intermediate Values Plot
/home/docs/checkouts/readthedocs.org/user_builds/optuna/checkouts/stable/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.298 秒)

由 Sphinx-Gallery 生成的画廊