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

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.002414635251466, (x - 2)^2: 5.830463397622336e-06

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

注解

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

Study 对象

下面是几个常用术语:

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

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

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

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

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

Out:

{'x': 2.002414635251466}

获得最佳目标函数值:

study.best_value

Out:

5.830463397622336e-06

获得最佳 trial:

study.best_trial

Out:

FrozenTrial(number=85, values=[5.830463397622336e-06], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 886143), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 888942), params={'x': 2.002414635251466}, distributions={'x': UniformDistribution(high=10.0, low=-10.0)}, user_attrs={}, system_attrs={}, intermediate_values={}, trial_id=85, state=TrialState.COMPLETE, value=None)

获得所有 trials:

study.trials

Out:

[FrozenTrial(number=0, values=[33.0574344023646], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 656820), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 657150), params={'x': 7.749559496375753}, 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=[71.91661440401204], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 657435), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 657687), params={'x': -6.480366407414955}, 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=[141.67529526343063], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 657927), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 658177), params={'x': -9.90274318228494}, 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=[1.5973302374987626], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 658412), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 658648), params={'x': 3.263855307184633}, 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=[55.46115221953139], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 658881), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 659116), params={'x': -5.4472244641565215}, 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=[52.98447966843003], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 659349), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 659585), params={'x': -5.279043870483955}, 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=[28.750715021065442], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 659817), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 660070), params={'x': -3.3619693230253977}, 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=[75.15406815283838], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 660302), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 660545), params={'x': -6.669144603294974}, 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=[90.35304478351169], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 660774), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 661019), params={'x': -7.505421862469424}, 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.0425931775227264], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 661250), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 661495), params={'x': 0.5708068088873617}, 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=[13.111054954989132], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 661727), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 664478), params={'x': 5.620919076006689}, 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.2938561333497465], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 664759), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 667578), params={'x': 2.5420849872019575}, 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=[0.005957167846807503], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 667862), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 670419), params={'x': 1.9228173086320028}, 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=[4.311781240098363], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 670698), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 673199), params={'x': -0.07648290147026326}, 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=[0.00027523597926880513], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 673479), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 675975), params={'x': 1.9834097625312714}, 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=[16.172969002733623], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 676254), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 678770), params={'x': -2.021563004943926}, 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=[58.89424650008066], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 679050), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 681568), params={'x': 9.674258693846635}, 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=[8.263413230814102], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 681848), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 684347), params={'x': 4.874615318753816}, 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=[0.7382479945076478], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 684630), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 687142), params={'x': 1.1407864092627213}, 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=[11.08407381871113], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 687424), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 689931), params={'x': -1.3292752692907703}, 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=[25.46629130245584], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 690240), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 692734), params={'x': 7.046413707025598}, 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.6146893170832086], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 693017), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 695551), params={'x': 2.7840212478518733}, 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=[1.0899912664622131], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 695830), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 698371), params={'x': 3.044026468276649}, 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=[0.23083316824307892], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 698655), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 701093), params={'x': 2.4804510050390975}, 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=[0.24675105864741156], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 701378), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 703821), params={'x': 1.5032595661239045}, 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=[8.098688375262416], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 704107), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 706574), params={'x': 4.845819455844382}, 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=[9.132959933056], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 706858), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 709294), params={'x': -1.0220787436888537}, 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=[3.9325831991917384], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 709577), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 712068), params={'x': 3.983074178943324}, 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=[24.661996490555794], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 712353), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 714867), params={'x': -2.966084623781173}, 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=[25.88973828017812], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 715152), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 717749), params={'x': 7.088195975016894}, 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=[0.12276042150166358], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 718036), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 720661), params={'x': 1.649628166797524}, 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.05199534927277305], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 720952), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 723595), params={'x': 1.7719751126022139}, 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.284141180448658], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 723885), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 726524), params={'x': 1.4669510524833034}, 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=[4.586554492620153], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 726810), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 729433), params={'x': -0.14162426504280923}, 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=[12.665180189034121], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 729725), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 732605), params={'x': 5.558817245804303}, 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=[4.006482451897673], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 732894), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 735558), params={'x': 4.001619956909321}, 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=[0.007772204005382026], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 735849), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 738503), params={'x': 1.9118398956138207}, 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=[4.772376968169341], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 738793), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 741431), params={'x': -0.18457706848930822}, 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=[23.106324112059127], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 741723), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 744369), params={'x': -2.8069037968383688}, 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=[37.33537443227175], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 744662), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 747314), params={'x': -4.110267950938956}, 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=[44.37446828830313], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 747604), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 750292), params={'x': 8.661416387548757}, 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.10345096544527062], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 750583), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 753238), params={'x': 1.678362058448835}, 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.01144817925641289], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 753530), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 756207), params={'x': 2.106996164680856}, 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=[2.459706236515906], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 756498), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 759441), params={'x': 3.568345062961562}, 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=[2.268004806272192], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 759733), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 762419), params={'x': 0.494010356518946}, 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=[11.073497397713343], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 762710), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 765606), params={'x': -1.3276864933033194}, 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=[0.11993627560067824], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 765900), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 768575), params={'x': 2.346318171051821}, 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=[7.448848091529441], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 768871), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 771566), params={'x': 4.729257791328888}, 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=[1.2491501873139628], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 771861), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 774559), params={'x': 0.8823461236527819}, 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=[5.289537312259115], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 774856), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 777527), params={'x': -0.29989941350901583}, 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=[15.086335060450315], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 777825), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 780564), params={'x': 5.884113162673085}, 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.0023666300487670865], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 780864), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 783571), params={'x': 1.9513519779562716}, 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.011165325943940992], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 783870), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 786569), params={'x': 2.1056661059372446}, 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=[2.8496157852121096], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 786869), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 789571), params={'x': 3.6880805031787167}, 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=[0.4494354431494757], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 789884), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 792606), params={'x': 2.6703994653558993}, 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=[1.9086334714358546], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 792907), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 795649), params={'x': 0.6184669850358788}, 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=[0.04876238930501794], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 795952), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 798667), params={'x': 2.2208220761269533}, 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=[8.166539717719276], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 798969), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 801712), params={'x': -0.8577158217218304}, 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=[6.223037759569742], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 802015), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 804728), params={'x': 4.494601723636409}, 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=[142.4333719611368], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 805032), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 808729), params={'x': -9.934545318575685}, 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=[1.9458528215550372], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 809028), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 811784), params={'x': 3.394938285930613}, 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.026899124937868602], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 812090), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 814814), params={'x': 2.1640095269728823}, 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.9350760414799577], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 815116), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 817848), params={'x': 2.966993299604479}, 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.1960439650948327], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 818164), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 820904), params={'x': 0.9063620502676251}, 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=[0.015884038597912473], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 821208), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 823970), params={'x': 1.8739681048388446}, 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=[2.4324618734505963], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 824272), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 827016), params={'x': 0.440364826810258}, 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.6638604421666308], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 827323), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 830083), params={'x': 1.1852236858090248}, 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=[15.389846529416964], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 830389), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 833140), params={'x': -1.9229894888231558}, 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=[4.829477329593954], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 833444), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 836197), params={'x': 4.197607182731699}, 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=[1.2930217999918523], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 836502), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 839268), params={'x': 3.1371111643071017}, 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=[12.964606731860862], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 839575), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 842356), params={'x': 5.600639767022086}, 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.06423955990256958], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 842663), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 845447), params={'x': 2.2534552424049847}, 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=[3.819775102927247e-05], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 845754), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 848527), params={'x': 1.9938195670839922}, 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=[0.008859765916553328], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 848835), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 851642), params={'x': 1.905873670439386}, 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=[0.37824509177236815], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 851950), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 854730), params={'x': 1.384983665442642}, 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=[3.13077333110614], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 855040), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 857812), params={'x': 0.2306008559100805}, 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=[6.953421733068421], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 858135), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 860904), params={'x': -0.6369341541017705}, 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.7556060919069976], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 861212), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 863994), params={'x': 2.869256056583443}, 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.6859171001568559], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 864303), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 867140), params={'x': 1.1717988769888947}, 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=[119.6163594323052], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 867450), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 870261), params={'x': -8.936926416151167}, 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=[2.2363284049230416], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 870575), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 873350), params={'x': 3.495435857843138}, 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.03198596947325318], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 873666), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 876460), params={'x': 1.821153782614076}, 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.0013306777381771472], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 876773), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 879575), params={'x': 1.9635215441914389}, 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.5489191182163721], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 879888), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 882714), params={'x': 2.7408907599750263}, 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.6960322140010677], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 883028), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 885819), params={'x': 0.07749324734578167}, 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=[5.830463397622336e-06], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 886143), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 888942), params={'x': 2.002414635251466}, 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=[1.516052247439232], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 889259), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 892085), params={'x': 0.7687192653828974}, 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=[4.763359319958695], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 892402), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 895223), params={'x': 4.182512158032274}, 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=[0.12210067088342366], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 895540), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 898357), params={'x': 1.6505709358347196}, 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=[10.416202988526841], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 898671), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 901497), params={'x': 5.22741428833158}, 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.31127399895379826], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 901813), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 904654), params={'x': 2.5579193480726388}, 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.002962799509529825], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 904969), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 907812), params={'x': 2.05443160395882}, 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.39710817791172975], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 908152), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 910999), params={'x': 1.3698348010944037}, 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=[1.4665260288901159], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 911317), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 914163), params={'x': 3.211002076336005}, 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=[3.2212152028220262], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 914481), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 917310), params={'x': 3.7947744155804166}, 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.01308049012798787], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 917629), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 920485), params={'x': 2.1143699703942773}, 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=[0.9787346471031203], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 920803), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 923649), params={'x': 1.0106898124940185}, 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=[0.5903495981624061], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 923967), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 926814), params={'x': 2.7683421101061727}, 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=[0.017650854307870202], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 927134), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 929976), params={'x': 1.8671434822529576}, 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=[6.24084010830879], datetime_start=datetime.datetime(2021, 5, 28, 3, 8, 46, 930320), datetime_complete=datetime.datetime(2021, 5, 28, 3, 8, 46, 933149), params={'x': -0.49816734994050993}, 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.002414635251466, (x - 2)^2: 5.830463397622336e-06

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

Gallery generated by Sphinx-Gallery