hyperas optim中的max eval参数最小化函数返回值是什么? - python

我正在尝试使用Hyperas调整参数,但无法解释一些细节。

Q1)optim.minimize中的max_eval参数是什么?

Q2)是否会针对每个max_eval遍历参数的每个组合,并根据最佳参数给我带来最佳损失?

Q3)如果我给max_eval = 5怎么办?

Q4)完成所有max_evals之后,best_run和best_model返回什么?

Q5)在下面的模型函数中,我以-test_acc的形式返回了损失,它与调整参数有什么关系,为什么我们在此处使用负号?

def model(x_train, y_train, x_test, y_test):    

    dense_units1 = {{choice([64, 126, 256, 512])}}
    activations = {{choice(['relu', 'sigmoid'])}}

    epochs  = 100
    verbose = 0

    model = Sequential([
        # layer 1
        Dense(dense_units1, activations, input_shape=(784,)),
               ....
               ....
               ....

    ])
    # compiling model
    model.compile(optimizers, loss='categorical_crossentropy', metrics=['accuracy'])
    # fitting the model
    result = model.fit(x_train, y_train, validation_split=0.2, batch_size=batch_size, 
                        epochs=epochs, verbose=verbose, callbacks=[ES, MC])

    test_loss, test_acc = model.evaluate(x_test, y_test, batch_size=512)

    return {'loss': -test_acc, 'status': STATUS_OK, 'model': model}

best_run, best_model = optim.minimize(model=model, data=dataset, algo=tpe.suggest, 
                                       max_evals=5, 
                                      trials=Trials(), notebook_name='MNIST', 
                                      verbose=True)

python大神给出的解决方案

max_eval参数只是优化运行的最大次数。 (例如,如果max_evals = 5,Hyperas将选择5次不同的超参数组合,并针对您选择的时期数运行每种组合)
不,它将对每个max_eval进行超参数的一种组合。超参数的最佳组合是在完成您在max_eval参数中给出的所有评估之后。
在第一季度回答。
在这种情况下,best_modelbest_run将返回相同的值。您应该将此添加到您的代码中:

print('Best performing model chosen hyper-parameters:')
print(best_run)

这将从所有运行中打印出最佳的超参数。

Python sqlite3数据库已锁定 - python

我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…

Python:同时在for循环中添加到列表列表 - python

我想用for循环外的0索引值创建一个新列表,然后使用for循环添加到相同的列表。我的玩具示例是:import random data = ['t1', 't2', 't3'] masterlist = [['col1', 'animal1', 'an…

在Python中迭代OrderedDict - python

我有以下OrderedDict:OrderedDict([('r', 1), ('s', 1), ('a', 1), ('n', 1), ('y', 1)]) 实际上,这表示单词中字母的出现频率。第一步-我将使用最后两个元素来创建一个这样的联合元组; pair…

如何在Matplotlib条形图后面绘制网格线 - python

x = ['01-02', '02-02', '03-02', '04-02', '05-02'] y = [2, 2, 3, 7, 2] fig, ax = plt.subplots(1, 1) ax.bar(range(len(y)), y, width=…