贝叶斯搜索最佳参数

model=XGBClassifier(learning_rate=0.96,
                   n_estimators=91,
                   max_depth=2,
                   min_child_weight=1,
                   objective='binary:logistic',
                   subsample=0.9,
                    feature_fraction=0.5,
#                     reg_alpha=8,
#                     reg_lambda=12,
#                    colsample_bytree=0.99,
#                    nthread=8,
#                    scale_pos_weight=1,
                   seed=1330)
def rf_cv(learning_rate,n_estimators, max_depth, min_child_weight,subsample,reg_alpha,reg_lambda):
    val = cross_val_score(
       XGBClassifier(
            
                            learning_rate=learning_rate,
                            n_estimators=int(n_estimators),
                            max_depth=int(max_depth),
                            min_child_weight=min_child_weight,
                            subsample=min(subsample, 0.999),
                           # num_leaves=int(num_leaves),
                            reg_alpha=int(reg_alpha),
                            reg_lambda=int(reg_lambda)
                            # feature_fraction=min(feature_fraction, 0.999),
                            # random_state=int(random_state)
        ),
        train_x, train_y, scoring='roc_auc', cv=5
    ).mean()
    return val
params= {
                'learning_rate': (0.1, 1.5),
                'n_estimators': (1, 100),
                'max_depth': (1, 100),
                'min_child_weight': (0.1, 0.999),
                'subsample': (0.1, 0.999),
                 #'num_leaves':(1,200),
                
               # 'feature_fraction': (0.1, 0.999),
                #'random_state': (2, 2500),
                'reg_alpha':(1,9),
                'reg_lambda':(5,20),
        
        
        }
#实例化贝叶斯优化函数
rf_bo = BayesianOptimization(rf_cv, params)
#最大化目标函数,贝叶斯中只能最大化目标函数,因此当需要求最小化目标函数时,需要将目标函数取相反数。
rf_bo.maximize(init_points=5,n_iter=50)
params=rf_bo.max
params=params["params"]
params#打印最优参数
val=rf_cv(**params)
val#打印交叉准确率
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追梦小狂魔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值