轻量级、多功能和跨平台架构

Optuna 完全由 Python 写成,并且只有少量依赖。这意味着一旦你开始对 Optuna 感兴趣,我们可以快速上手真实的例子。

二次函数的例子

通常,Optuna是用于优化超参数的,但是作为例子,我们这里来优化一个简单的而此函数:\((x - 2)^2\).

首先,导入 optuna.

import optuna

在 Optuna 中,待优化函数一般被命名为 objective.

def objective(trial):
    x = trial.suggest_float("x", -10, 10)
    return (x - 2) ** 2

该函数的返回值是 \((x - 2)^2\). 我们的目标是找到一个 x,使 objective 函数的输出最小。这被称为 “optimization” (优化)。 在优化过程中,Optuna 反复调用目标函数,在不同的 x 下对其进行求值。

一个 Trial 对应着目标函数的单次执行。在每次调用该函数的时候,它都被内部实例化一次。

suggest API (例如 suggest_uniform()) 在目标函数内部被调用。它被用于获取单个 trial 的参数。在上面的例子中,suggest_uniform() 在给定的范围(-1010)内均匀地选择参数。

为了开始优化过程,我们将创建一个 study 对象,并将目标函数传递给它的一个方法 optimize()

study = optuna.create_study()
study.optimize(objective, n_trials=100)

You can get the best parameter as follows.

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 2.0152299314649573, (x - 2)^2: 0.00023195081242729718

最佳参数可以通过如下方式获得:

注解

当 Optuna 被用于机器学习时,目标函数通常返回模型的损失或者准确度。

Study 对象

下面是几个常用术语:

  • Trial: 目标函数的单次调用

  • Study: 一次优化过程,包含一系列的 trials.

  • Parameter: 待优化的参数,比如上面例子中的 x.

在 Optuna 中,我们用 study 对象来管理优化过程。 create_study() 方法会返回一个 study 对象。该对象包含若干有用的属性,可以用于分析优化结果。

获得参数名和参数值的字典:

Out:

{'x': 2.0152299314649573}

获得最佳目标函数值:

study.best_value

Out:

0.00023195081242729718

获得最佳 trial:

study.best_trial

Out:

FrozenTrial(number=22, values=[0.00023195081242729718], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 285642), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 288453), params={'x': 2.0152299314649573}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=22, state=TrialState.COMPLETE, value=None)

获得所有 trials:

study.trials

Out:

[FrozenTrial(number=0, values=[88.85304463942546], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 241954), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 242206), params={'x': -7.426189295756025}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=0, state=TrialState.COMPLETE, value=None), FrozenTrial(number=1, values=[7.800617916849969], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 242519), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 242754), params={'x': -0.7929586314247423}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=1, state=TrialState.COMPLETE, value=None), FrozenTrial(number=2, values=[6.816139167836155], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 243019), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 243233), params={'x': -0.6107736722734423}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=2, state=TrialState.COMPLETE, value=None), FrozenTrial(number=3, values=[77.10945513410554], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 243486), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 243709), params={'x': -6.781198957665493}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=3, state=TrialState.COMPLETE, value=None), FrozenTrial(number=4, values=[6.325515804935463], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 243961), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 244173), params={'x': 4.515057813437986}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=4, state=TrialState.COMPLETE, value=None), FrozenTrial(number=5, values=[88.19625439161206], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 244419), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 244633), params={'x': -7.391286088263527}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=5, state=TrialState.COMPLETE, value=None), FrozenTrial(number=6, values=[85.00536839189974], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 244926), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 245119), params={'x': -7.21983559462422}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=6, state=TrialState.COMPLETE, value=None), FrozenTrial(number=7, values=[7.9040630214192245], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 245366), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 245556), params={'x': -0.8114165506767623}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=7, state=TrialState.COMPLETE, value=None), FrozenTrial(number=8, values=[0.12243648168914782], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 245800), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 245992), params={'x': 2.3499092477902632}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=8, state=TrialState.COMPLETE, value=None), FrozenTrial(number=9, values=[2.9221201812003548], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 246239), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 246433), params={'x': 0.2905789924069744}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=9, state=TrialState.COMPLETE, value=None), FrozenTrial(number=10, values=[33.4783626037012], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 246679), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 250671), params={'x': 7.7860489631268415}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=10, state=TrialState.COMPLETE, value=None), FrozenTrial(number=11, values=[0.40879600857592097], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 250944), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 254177), params={'x': 2.6393715731684675}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=11, state=TrialState.COMPLETE, value=None), FrozenTrial(number=12, values=[3.5174393800989], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 254450), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 257333), params={'x': 3.8754837722835407}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=12, state=TrialState.COMPLETE, value=None), FrozenTrial(number=13, values=[2.142096736458277], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 257610), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 260709), params={'x': 3.4635903581461163}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=13, state=TrialState.COMPLETE, value=None), FrozenTrial(number=14, values=[63.24696660046356], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 260987), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 263775), params={'x': 9.952796149811936}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=14, state=TrialState.COMPLETE, value=None), FrozenTrial(number=15, values=[30.687266717114927], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 264048), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 266844), params={'x': -3.539608895681619}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=15, state=TrialState.COMPLETE, value=None), FrozenTrial(number=16, values=[0.05660837842352986], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 267112), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 269925), params={'x': 2.2379251529862487}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=16, state=TrialState.COMPLETE, value=None), FrozenTrial(number=17, values=[27.72677651949958], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 270197), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 273003), params={'x': 7.265622139833011}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=17, state=TrialState.COMPLETE, value=None), FrozenTrial(number=18, values=[29.493065093630754], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 273273), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 276091), params={'x': -3.4307517981979947}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=18, state=TrialState.COMPLETE, value=None), FrozenTrial(number=19, values=[18.43970566188413], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 276362), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 279148), params={'x': 6.294147838848137}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=19, state=TrialState.COMPLETE, value=None), FrozenTrial(number=20, values=[0.40026797455251334], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 279417), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 282245), params={'x': 1.367332650951139}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=20, state=TrialState.COMPLETE, value=None), FrozenTrial(number=21, values=[0.15143560113121826], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 282516), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 285372), params={'x': 1.610852725653618}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=21, state=TrialState.COMPLETE, value=None), FrozenTrial(number=22, values=[0.00023195081242729718], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 285642), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 288453), params={'x': 2.0152299314649573}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=22, state=TrialState.COMPLETE, value=None), FrozenTrial(number=23, values=[24.383724004721568], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 288727), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 291532), params={'x': -2.93798784979485}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=23, state=TrialState.COMPLETE, value=None), FrozenTrial(number=24, values=[11.185908496150992], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 291820), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 294617), params={'x': 5.344534122437831}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=24, state=TrialState.COMPLETE, value=None), FrozenTrial(number=25, values=[0.005255121755103693], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 294903), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 297731), params={'x': 1.9275077814168742}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=25, state=TrialState.COMPLETE, value=None), FrozenTrial(number=26, values=[15.827359658714657], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 298006), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 300848), params={'x': -1.9783614288692597}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=26, state=TrialState.COMPLETE, value=None), FrozenTrial(number=27, values=[1.379346456690261], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 301123), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 303959), params={'x': 0.8255441869996722}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=27, state=TrialState.COMPLETE, value=None), FrozenTrial(number=28, values=[49.13176409446846], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 304235), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 307124), params={'x': -5.009405402348223}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=28, state=TrialState.COMPLETE, value=None), FrozenTrial(number=29, values=[7.933741435911127], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 307401), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 310313), params={'x': 4.816689801151544}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=29, state=TrialState.COMPLETE, value=None), FrozenTrial(number=30, values=[61.364334770011666], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 310622), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 313588), params={'x': 9.833539096092625}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=30, state=TrialState.COMPLETE, value=None), FrozenTrial(number=31, values=[0.23004704192195222], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 313866), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 316808), params={'x': 2.4796321944177144}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=31, state=TrialState.COMPLETE, value=None), FrozenTrial(number=32, values=[0.18348468739704565], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 317086), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 320002), params={'x': 2.4283511262936583}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=32, state=TrialState.COMPLETE, value=None), FrozenTrial(number=33, values=[5.402400648026345], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 320281), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 323177), params={'x': -0.32430648754125047}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=33, state=TrialState.COMPLETE, value=None), FrozenTrial(number=34, values=[1.14669538452007], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 323457), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 326401), params={'x': 3.070838636079251}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=34, state=TrialState.COMPLETE, value=None), FrozenTrial(number=35, values=[0.23512739604284338], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 326682), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 329626), params={'x': 1.5151006330764667}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=35, state=TrialState.COMPLETE, value=None), FrozenTrial(number=36, values=[12.438555917455183], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 329905), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 332826), params={'x': -1.5268336957468214}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=36, state=TrialState.COMPLETE, value=None), FrozenTrial(number=37, values=[10.34730670895612], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 333106), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 336059), params={'x': 5.216722976719649}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=37, state=TrialState.COMPLETE, value=None), FrozenTrial(number=38, values=[3.3817782967216563], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 336337), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 339245), params={'x': 0.1610387995605626}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=38, state=TrialState.COMPLETE, value=None), FrozenTrial(number=39, values=[136.25114264905], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 339524), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 342472), params={'x': -9.672666475533772}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=39, state=TrialState.COMPLETE, value=None), FrozenTrial(number=40, values=[3.764110257874023], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 342753), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 345709), params={'x': 3.940131505304221}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=40, state=TrialState.COMPLETE, value=None), FrozenTrial(number=41, values=[0.0786083931549398], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 345990), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 348954), params={'x': 1.7196281163259415}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=41, state=TrialState.COMPLETE, value=None), FrozenTrial(number=42, values=[0.004084961958512018], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 349236), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 352205), params={'x': 1.9360862928745952}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=42, state=TrialState.COMPLETE, value=None), FrozenTrial(number=43, values=[1.2617974387595958], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 352485), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 355433), params={'x': 0.8767024264427543}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=43, state=TrialState.COMPLETE, value=None), FrozenTrial(number=44, values=[11.361031880862425], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 355727), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 358665), params={'x': -1.3706129829546474}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=44, state=TrialState.COMPLETE, value=None), FrozenTrial(number=45, values=[0.000728876046254758], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 358947), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 362222), params={'x': 1.9730022955373099}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=45, state=TrialState.COMPLETE, value=None), FrozenTrial(number=46, values=[5.808997474855934], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 362507), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 365499), params={'x': -0.41018619091055575}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=46, state=TrialState.COMPLETE, value=None), FrozenTrial(number=47, values=[4.913385993401843], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 365782), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 368761), params={'x': 4.216615887654386}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=47, state=TrialState.COMPLETE, value=None), FrozenTrial(number=48, values=[18.066584478592986], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 369044), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 372022), params={'x': 6.250480499730941}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=48, state=TrialState.COMPLETE, value=None), FrozenTrial(number=49, values=[2.369623457921158], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 372305), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 375281), params={'x': 3.539358131794274}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=49, state=TrialState.COMPLETE, value=None), FrozenTrial(number=50, values=[1.4101049178233385], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 375566), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 378530), params={'x': 0.8125216137447644}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=50, state=TrialState.COMPLETE, value=None), FrozenTrial(number=51, values=[0.013300521639103911], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 378814), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 381805), params={'x': 1.8846721124831296}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=51, state=TrialState.COMPLETE, value=None), FrozenTrial(number=52, values=[0.8646009515025257], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 382090), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 385104), params={'x': 2.9298392073377664}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=52, state=TrialState.COMPLETE, value=None), FrozenTrial(number=53, values=[0.0688598907250087], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 385392), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 388395), params={'x': 2.2624116817617095}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=53, state=TrialState.COMPLETE, value=None), FrozenTrial(number=54, values=[2.5686159650700806], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 388683), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 391676), params={'x': 0.3973097725792172}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=54, state=TrialState.COMPLETE, value=None), FrozenTrial(number=55, values=[0.10475142020930689], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 391966), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 394974), params={'x': 1.6763467593097408}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=55, state=TrialState.COMPLETE, value=None), FrozenTrial(number=56, values=[1.4158174673528408], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 395262), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 398309), params={'x': 3.189881282881969}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=56, state=TrialState.COMPLETE, value=None), FrozenTrial(number=57, values=[5.6394046244728955], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 398598), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 404519), params={'x': 4.3747430649383725}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=57, state=TrialState.COMPLETE, value=None), FrozenTrial(number=58, values=[15.248737785151004], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 404823), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 407881), params={'x': 5.904963224558076}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=58, state=TrialState.COMPLETE, value=None), FrozenTrial(number=59, values=[9.188062453448149], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 408172), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 411179), params={'x': -1.0311816925826385}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=59, state=TrialState.COMPLETE, value=None), FrozenTrial(number=60, values=[20.918243887147298], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 411469), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 414498), params={'x': -2.573646672748923}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=60, state=TrialState.COMPLETE, value=None), FrozenTrial(number=61, values=[0.06998460297426203], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 414804), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 417844), params={'x': 2.264546031862627}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=61, state=TrialState.COMPLETE, value=None), FrozenTrial(number=62, values=[0.04401422352338943], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 418135), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 421186), params={'x': 2.2097956708881035}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=62, state=TrialState.COMPLETE, value=None), FrozenTrial(number=63, values=[1.4618099986971556], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 421479), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 424543), params={'x': 0.7909466518398969}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=63, state=TrialState.COMPLETE, value=None), FrozenTrial(number=64, values=[2.8787931589800606], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 424852), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 427901), params={'x': 3.696700668644903}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=64, state=TrialState.COMPLETE, value=None), FrozenTrial(number=65, values=[0.0049694207053338395], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 428194), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 431218), params={'x': 1.929505881767811}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=65, state=TrialState.COMPLETE, value=None), FrozenTrial(number=66, values=[0.021027559878723758], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 431513), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 434586), params={'x': 1.8549911731006565}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=66, state=TrialState.COMPLETE, value=None), FrozenTrial(number=67, values=[3.7565124701467143], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 434900), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 437962), params={'x': 0.06182754375501598}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=67, state=TrialState.COMPLETE, value=None), FrozenTrial(number=68, values=[0.6742801784789625], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 438258), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 441337), params={'x': 1.1788543500212874}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=68, state=TrialState.COMPLETE, value=None), FrozenTrial(number=69, values=[0.8662314409585098], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 441667), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 444775), params={'x': 2.9307155531946965}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=69, state=TrialState.COMPLETE, value=None), FrozenTrial(number=70, values=[0.11686090364732946], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 445071), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 448444), params={'x': 1.6581507588902245}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=70, state=TrialState.COMPLETE, value=None), FrozenTrial(number=71, values=[0.06650900807607328], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 448742), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 451809), params={'x': 2.2578934044834673}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=71, state=TrialState.COMPLETE, value=None), FrozenTrial(number=72, values=[0.0005184844509247064], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 452105), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 455168), params={'x': 1.977229746357919}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=72, state=TrialState.COMPLETE, value=None), FrozenTrial(number=73, values=[2.4373772870878976], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 455465), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 458535), params={'x': 0.43878980047916105}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=73, state=TrialState.COMPLETE, value=None), FrozenTrial(number=74, values=[6.20370614406122], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 458830), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 461911), params={'x': -0.4907240200514429}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=74, state=TrialState.COMPLETE, value=None), FrozenTrial(number=75, values=[2.1338344389990946], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 462207), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 465288), params={'x': 3.4607650184061414}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=75, state=TrialState.COMPLETE, value=None), FrozenTrial(number=76, values=[0.5937037808537524], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 465584), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 468655), params={'x': 1.2294782411548961}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=76, state=TrialState.COMPLETE, value=None), FrozenTrial(number=77, values=[0.8605331517217428], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 468951), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 472038), params={'x': 2.9276492611551754}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=77, state=TrialState.COMPLETE, value=None), FrozenTrial(number=78, values=[0.045793182670226903], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 472335), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 475410), params={'x': 1.78600658264744}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=78, state=TrialState.COMPLETE, value=None), FrozenTrial(number=79, values=[6.127305600159406], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 475724), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 478789), params={'x': 4.4753394918999305}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=79, state=TrialState.COMPLETE, value=None), FrozenTrial(number=80, values=[8.055696194476221], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 479088), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 482169), params={'x': 4.838255836684956}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=80, state=TrialState.COMPLETE, value=None), FrozenTrial(number=81, values=[0.020566029924400275], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 482468), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 485569), params={'x': 2.1434086117511786}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=81, state=TrialState.COMPLETE, value=None), FrozenTrial(number=82, values=[0.7444811151215247], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 485869), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 489274), params={'x': 1.1371668092142464}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=82, state=TrialState.COMPLETE, value=None), FrozenTrial(number=83, values=[0.02654040690666951], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 489573), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 493022), params={'x': 1.8370877324856427}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=83, state=TrialState.COMPLETE, value=None), FrozenTrial(number=84, values=[3.4783746899870733], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 493323), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 496451), params={'x': 3.8650401309320594}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=84, state=TrialState.COMPLETE, value=None), FrozenTrial(number=85, values=[0.5506059108658413], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 496753), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 499853), params={'x': 2.742028241285897}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=85, state=TrialState.COMPLETE, value=None), FrozenTrial(number=86, values=[4.468444178159306], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 500154), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 503231), params={'x': -0.11386947992521668}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=86, state=TrialState.COMPLETE, value=None), FrozenTrial(number=87, values=[2.111324230183641], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 503531), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 506632), params={'x': 0.546960348034631}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=87, state=TrialState.COMPLETE, value=None), FrozenTrial(number=88, values=[1.8598238453448597], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 506935), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 510088), params={'x': 3.363753586739503}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=88, state=TrialState.COMPLETE, value=None), FrozenTrial(number=89, values=[0.0017508271715622533], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 510391), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 513527), params={'x': 2.0418428867498677}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=89, state=TrialState.COMPLETE, value=None), FrozenTrial(number=90, values=[0.4936441296020133], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 513829), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 516982), params={'x': 2.702598128094584}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=90, state=TrialState.COMPLETE, value=None), FrozenTrial(number=91, values=[0.0021849756074579156], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 517285), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 520406), params={'x': 2.0467437226529714}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=91, state=TrialState.COMPLETE, value=None), FrozenTrial(number=92, values=[0.6200846249856551], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 520709), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 523915), params={'x': 1.2125454775127296}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=92, state=TrialState.COMPLETE, value=None), FrozenTrial(number=93, values=[0.00032858887835949597], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 524218), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 527347), params={'x': 1.9818729793303065}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=93, state=TrialState.COMPLETE, value=None), FrozenTrial(number=94, values=[0.4217941042152049], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 527666), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 531017), params={'x': 2.649456776248585}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=94, state=TrialState.COMPLETE, value=None), FrozenTrial(number=95, values=[0.42247220560028853], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 531325), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 534454), params={'x': 1.3500213806591108}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=95, state=TrialState.COMPLETE, value=None), FrozenTrial(number=96, values=[8.216038514766556], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 534772), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 537913), params={'x': -0.8663632907861758}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=96, state=TrialState.COMPLETE, value=None), FrozenTrial(number=97, values=[1.8706593793185327], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 538218), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 541359), params={'x': 0.6322794951750805}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=97, state=TrialState.COMPLETE, value=None), FrozenTrial(number=98, values=[1.6004766342158443], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 541664), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 544822), params={'x': 3.265099456254663}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=98, state=TrialState.COMPLETE, value=None), FrozenTrial(number=99, values=[0.0036267586101895494], datetime_start=datetime.datetime(2021, 4, 10, 21, 5, 5, 545127), datetime_complete=datetime.datetime(2021, 4, 10, 21, 5, 5, 548267), params={'x': 1.939777424414182}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=99, state=TrialState.COMPLETE, value=None)]

获得 trial 的数目:

len(study.trials)

Out:

100

再次执行 optimize(),我们可以继续优化过程。

study.optimize(objective, n_trials=100)

获得更新后的的 trial 数量:

len(study.trials)

Out:

200

由于此目标函数非常简单,所以后面的 100 个trial 并没有提升结果。然而,我们可以再一次检查该结果:

best_params = study.best_params
found_x = best_params["x"]
print("Found x: {}, (x - 2)^2: {}".format(found_x, (found_x - 2) ** 2))

Out:

Found x: 2.0060170122018133, (x - 2)^2: 3.620443583676985e-05

Total running time of the script: ( 0 minutes 0.698 seconds)

Gallery generated by Sphinx-Gallery