2

我正在试验 Hyperopt 和 scikit-learn。据我所知,您只需要{'status':STATUS_FAIL}为没有收敛的情况提供字典,但我面临错误消息。我不太确定我是否在返回的字典中遗漏了一些数据、参数或键,我是否误解了有关 Hyperopt 使用的某些内容。

认为它可能是字典中的任何附加和必要元素,我已经尝试了一些组合,例如:

{'status': STATUS_FAIL, 'loss': 1, 'params': params, 'test': [0, 0], 'train': [0, 0]}

我的代码如下所示:

def objective(params=None):
            '''Objective function for bayesian hyperparameter tuning'''
            if params:
                model.set_params(params)

            try:
                cv_results = cross_validate(model.pipeline, X, y, pids,
                                            scoring='roc_auc', cv=akf,
                                            n_jobs=-1, 
                                            return_train_score=True)
            except ValueError:
                return {'status': STATUS_FAIL }

            # Dictionary with information for evaluation
            return {'loss': 1 - np.mean(cv_results['test_score']),
                    'params': params, 'status': STATUS_OK,
                    'test': cv_results['test_score'],
                    'train': cv_results['train_score']}

这是我正在使用的目标函数:

    fmin(fn=objective, space=param_grid, algo=tpe.suggest,
         max_evals=iter, trials=bayes_trials,
         show_progressbar=not quiet)

收到的错误消息是:

Traceback (most recent call last):
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
AttributeError: 'list' object has no attribute 'argmin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
...
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/hyperopt/fmin.py", line 409, in fmin
    return trials.argmin
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/hyperopt/base.py", line 590, in argmin
    best_trial = self.best_trial
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/hyperopt/base.py", line 585, in best_trial
    best = np.argmin(losses)
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 1172, in argmin
    return _wrapfunc(a, 'argmin', axis=axis, out=out)
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 66, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "/home/evasd/miniconda3/envs/ir-models/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 46, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
ValueError: attempt to get argmin of an empty sequence
4

0 回答 0