2

使用 python 中的 hyperopt 库,我想优化神经网络的参数。有时,选择的参数组合会导致模型不稳定,从而导致模型构建过程崩溃。

现在,我创建了一个 try/except 异常处理程序,可以防止整个超参数优化过程停止。我面临的问题是,hyperopt 更新仍然整合了失败模型的(任意选择的)损失结果,以通知后续参数选择。我希望 hyperopt 忽略失败的模型。我的目标函数如下:

def objective_fn_for_ann_hyperopt(params, nfolds=5):

     config.ITERATION += 1
     try:
            model = h2o.estimators.H2ODeepLearningEstimator(
            activation='rectifier_with_dropout',
            rho=params['rho'],
            epsilon=params['epsilon'],
            max_w2=10.,
            epochs=params['epochs'],
            hidden=hidden,
            nfolds=nfolds,
            hidden_dropout_ratios=hidden_dropout_ratios,
            input_dropout_ratio=params['input_dropout_ratio'],
            l2=params['l2'],
            l1=1e-5,
            distribution=params['distribution'],
            stopping_metric='mse',
            stopping_tolerance=0.05,
            stopping_rounds=15,

            keep_cross_validation_predictions=True,
            fold_assignment="Modulo",

        )

            model.train(config.x, config.y, training_frame=config.train,
                        validation_frame=config.test)


            run_time = timer() - start

            loss = model._model_json['output']['cross_validation_metrics_summary'].as_data_frame(
            ).iloc[5]['mean']


            success = STATUS_OK #'ok'
        except:

            success = STATUS_FAIL  #'fail'              
            loss = 0 #arbitrary number
            run_time = timer() - start


        return {'loss': loss, 'params': params, 'iteration': config.ITERATION,

                'train_time': run_time, 'status': success}

如何与 hyperopt 更新程序通信,而不是整合失败模型的信息?

4

1 回答 1

1

This issue can be addressed by either omitting the loss key from the returned dictionary, or by setting it equal to None.

It's discussed in this pull request- https://github.com/hyperopt/hyperopt/pull/176

于 2020-07-16T01:22:20.287 回答