注意
跳到末尾 下载完整的示例代码。
plot_edf
- optuna.visualization.matplotlib.plot_edf(study, *, target=None, target_name='Objective Value')[source]
使用 Matplotlib 绘制一个 Study 的目标值 EDF (经验分布函数)。
注意,绘制 EDF 时仅考虑已完成的试验。
另请参阅
请参阅
optuna.visualization.plot_edf()
以获取示例,此函数可以替换为它。注意
请参阅 matplotlib.pyplot.legend 以调整生成的图例样式。
- 参数:
- 返回值:
一个
matplotlib.axes.Axes
对象。- 返回值类型:
注意
作为实验性功能在 v2.2.0 中添加。接口在更高版本中可能会更改,恕不另行通知。请参阅 https://github.com/optuna/optuna/releases/tag/v2.2.0。
以下代码片段展示了如何绘制 EDF。

/home/docs/checkouts/readthedocs.org/user_builds/optuna/checkouts/stable/docs/visualization_matplotlib_examples/optuna.visualization.matplotlib.edf.py:43: ExperimentalWarning:
plot_edf is experimental (supported from v2.2.0). The interface can change in the future.
<Axes: title={'center': 'Empirical Distribution Function Plot'}, xlabel='Objective Value', ylabel='Cumulative Probability'>
import math
import optuna
def ackley(x, y):
a = 20 * math.exp(-0.2 * math.sqrt(0.5 * (x**2 + y**2)))
b = math.exp(0.5 * (math.cos(2 * math.pi * x) + math.cos(2 * math.pi * y)))
return -a - b + math.e + 20
def objective(trial, low, high):
x = trial.suggest_float("x", low, high)
y = trial.suggest_float("y", low, high)
return ackley(x, y)
sampler = optuna.samplers.RandomSampler(seed=10)
# Widest search space.
study0 = optuna.create_study(study_name="x=[0,5), y=[0,5)", sampler=sampler)
study0.optimize(lambda t: objective(t, 0, 5), n_trials=500)
# Narrower search space.
study1 = optuna.create_study(study_name="x=[0,4), y=[0,4)", sampler=sampler)
study1.optimize(lambda t: objective(t, 0, 4), n_trials=500)
# Narrowest search space but it doesn't include the global optimum point.
study2 = optuna.create_study(study_name="x=[1,3), y=[1,3)", sampler=sampler)
study2.optimize(lambda t: objective(t, 1, 3), n_trials=500)
optuna.visualization.matplotlib.plot_edf([study0, study1, study2])
脚本总运行时间: (0 分 0.774 秒)