【问题标题】:TypeError for BayesianOptimization bayes_opt贝叶斯优化的 TypeError bayes_opt
【发布时间】:2020-05-19 06:22:03
【问题描述】:

我正在关注在线超参数调整教程,我正在尝试使用bayes_opt,但我收到此错误:

---> best_params = bo.res['max']['max_params']
TypeError: list indices must be integers or slices, not str

这是我的示例代码:

from bayes_opt import BayesianOptimization

bo= BayesianOptimization(xgb_evaluate, {'max_depth': (3, 7), 
                                             'gamma': (0, 1),
                                             'colsample_bytree': (0.3, 0.9)})
bo.maximize(init_points=3, n_iter=5, acq='ei')

best_params = bo.res['max']['max_params']

【问题讨论】:

    标签: xgboost bayesian hyperparameters


    【解决方案1】:

    很可能我使用的是更新版本的bayes_opt 并且API 发生了变化。为了得到最好的参数,我只需要搜索最大目标值,然后得到参数:

    params = max(xgb_bo.res, key=lambda x:x['target'])
    best_params = params['params']
    best_target = params['target']
    best_params['max_depth'] = int(best_params['max_depth'])
    print(best_target, best_params)
    

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 1970-01-01
      • 2019-09-14
      • 2019-09-22
      • 2014-02-21
      • 2019-09-26
      • 2019-01-12
      • 2021-06-03
      • 1970-01-01
      相关资源
      最近更新 更多