注意
跳转至末尾以下载完整示例代码。
plot_timeline
- optuna.visualization.matplotlib.plot_timeline(study)[source]
绘制 Study 的时间线。
另请参阅
请参阅
optuna.visualization.plot_timeline()
以获取示例。- 参数:
- 返回:
一个
matplotlib.axes.Axes
对象。- 返回类型:
注意
在 v3.2.0 中作为实验性功能添加。此接口在更高版本中可能会发生更改,恕不另行通知。请参阅 https://github.com/optuna/optuna/releases/tag/v3.2.0。
以下代码片段展示了如何绘制 Study 的时间线。

/home/docs/checkouts/readthedocs.org/user_builds/optuna/checkouts/stable/docs/visualization_matplotlib_examples/optuna.visualization.matplotlib.timeline.py:29: ExperimentalWarning:
plot_timeline is experimental (supported from v3.2.0). The interface can change in the future.
<Axes: title={'center': 'Timeline Plot'}, xlabel='Datetime', ylabel='Trial'>
import time
import optuna
def objective(trial):
x = trial.suggest_float("x", 0, 1)
time.sleep(x * 0.1)
if x > 0.8:
raise ValueError()
if x > 0.4:
raise optuna.TrialPruned()
return x**2
study = optuna.create_study(direction="minimize")
study.optimize(objective, n_trials=50, n_jobs=2, catch=(ValueError,))
optuna.visualization.matplotlib.plot_timeline(study)
脚本总运行时间: (0 分钟 1.973 秒)