首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目前,我正在尝试使用XGBRegressor优化BayesianOptimization。以下是代码:

目前,我正在尝试使用XGBRegressor优化BayesianOptimization。以下是代码:
EN

Stack Overflow用户
提问于 2021-11-17 15:54:00
回答 1查看 165关注 0票数 1

我想将回归应用于我的数据集。目前,我正在尝试使用XGBRegressor优化BayesianOptimization,但每次运行它时,我都会得到相同的错误。我不太熟悉机器的收入,所以我真的很感激我能得到的任何帮助。以下是代码:

代码语言:javascript
复制
optimizer = BayesianOptimization(f=xgboostcv,
                     domain=params,
                     model_type='GP',
                     acquisition_type='EI',
                     acquisition_jitter=0.05,
                     exact_feval=True,
                     maximize=True,
                     verbosity=True) 
optimizer.run_optimization(max_iter=20,verbosity=True)

这是一个错误:

代码语言:javascript
复制
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-27-921c3885d33d> in <module>
----> 1 optimizer = BayesianOptimization(f=xgboostcv,
  2                                  domain=params,
  3                                  model_type='GP',
  4                                  acquisition_type='EI',
  5                                  acquisition_jitter=0.05,

~\anaconda3\envs\sklearn\lib\site-packages\GPyOpt\methods\bayesian_optimization.py in 
__init__(self, f, domain, constraints, cost_withGradients, model_type, X, Y, 
initial_design_numdata, initial_design_type, acquisition_type, normalize_Y, 
exact_feval, acquisition_optimizer_type, model_update_interval, evaluator_type, 
batch_size, num_cores, verbosity, verbosity_model, maximize, de_duplication, **kwargs)
   92         self.constraints = constraints
   93         self.domain = domain
---> 94         self.space = Design_space(self.domain, self.constraints)
   95 
   96         # --- CHOOSE objective function

~\anaconda3\envs\sklearn\lib\site-packages\GPyOpt\core\task\space.py in 
__init__(self, space, constraints, store_noncontinuous)
   69 
   70         ## --- Transform input config space into the objects used to run the 
optimization
---> 71         self._translate_space(self.config_space)
   72         self._expand_space()
   73         self._compute_variables_indices()

~\anaconda3\envs\sklearn\lib\site-packages\GPyOpt\core\task\space.py in 
_translate_space(self, space)
   177         for i, d in enumerate(space):
   178             descriptor = deepcopy(d)
--> 179             descriptor['name'] = descriptor.get('name', 'var_' + str(i))
 180             descriptor['type'] = descriptor.get('type', 'continuous')
 181             if 'domain' not in descriptor:

 AttributeError: 'str' object has no attribute 'get'

以下是"params“对象规范:

代码语言:javascript
复制
params ={'max_depth': (2, 5),
     'learning_rate': (0.01, 0.3),
     'n_estimators': (1000, 2500),
     'gamma': (1., 0.01),
     'min_child_weight': (1, 10),
     'max_delta_step': (0, 0.1),
     'subsample': (0.5, 0.8),
     'colsample_bytree' :(0.1, 0.99),
     'reg_alpha':(0.1, 0.5), 
     'reg_lambda':(0.1, 0.9)
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-18 14:42:46

GPyOpt包以更详细的方式指定超参数空间(因此更灵活?)方法比其他流行的搜索方法。文档中有一些示例:https://gpyopt.readthedocs.io/en/latest/GPyOpt.core.task.html#GPyOpt.core.task.space.Design_space

代码语言:javascript
复制
space = [
    {'name': 'max_depth', 'type': 'discrete', 'domain': (2,3,4,5)},
    {'name': 'learning_rate', 'type': 'continuous', 'domain': (0.01, 0.3)},
    ...
]

对于这里来说,重要的是,域需要成为一个数据库列表。在回溯中,您可以看到代码在域上使用enumerate,而枚举dict只是枚举键,因此出现了对期望dict的字符串的抱怨。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70007602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档