gpt4 book ai didi

python - 优化后如何将多个超参数传给LightGBM?

转载 作者:行者123 更新时间:2023-12-05 03:57:42 31 4
gpt4 key购买 nike

我使用了另一种优化算法,它为我返回了 Light GBM 的最佳参数。

hyper_optimized_clf_classifier = Util.hp_opt(lgb.LGBMClassifier(silent=True, random_state=1), X, y, score, verbose=True,
n_estimators =(hp.quniform,50,500,50),
learning_rate =(hp.qloguniform, np.log(0.05), np.log(0.4),0.001),
min_child_weight =(hp.qloguniform,np.log(3),np.log(200),1),
reg_lambda = (hp.qloguniform, np.log(2), np.log(100),1),
num_leaves = (hp.qloguniform, np.log(5),np.log(64),1),
subsample = (hp.quniform, 0.5, 1, 0.05),
colsample_bytree = (hp.quniform, 0.4, 1, 0.05),
max_depth = (hp.quniform, 2, 15, 1),
subsample_freq = (hp.quniform, 1, 10, 1),
max_bin = (hp.qloguniform, np.log(15), np.log(1023),1),
max_evals=100)

如果我尝试 get_params,我会得到一个最佳优化参数的字典,我想将其传递给再次训练:

hyper_optimized_clf_classifier.get_params()


{'boosting_type': 'gbdt',
'class_weight': None,
'colsample_bytree': 0.45,
'importance_type': 'split',
'learning_rate': 0.057,
'max_depth': 14,
'min_child_samples': 20,
'min_child_weight': 20.0,
'min_split_gain': 0.0,
'n_estimators': 450,
'n_jobs': -1,
'num_leaves': 5,
'objective': None,
'random_state': 1,
'reg_alpha': 0.0,
'reg_lambda': 2.0,
'silent': True,
'subsample': 1.0,
'subsample_for_bin': 200000,
'subsample_freq': 6}

我尝试将这些参数作为值列表传递给 light gbm 以再次进行训练:

['gbdt', None, 0.45, 'split', 0.057, 14, 20, 20.0, 0.0, 450, -1, 5, None, 1, 0.0, 2.0, True, 1.0, 200000,6]

clf = lgb.LGBMClassifier(list(hyper_optimized_clf_classifier.get_params().values()))

但它不识别它。

"LightGBMError: Unknown boosting type gbdt,none,0.45,split,0.057,14,20,20.0,0.0,450,-1,5,none,1,0.0,2.0,true,1.0,200000,6"

最佳答案

这是一个基于问题数据和@ Misha's 的可重现示例评论以备将来引用。

from lightgbm import LGBMClassifier

lgbm_clf = LGBMClassifier()

lgbm_params = {
'colsample_bytree': 0.45,
'learning_rate': 0.057,
'max_depth': 14,
'min_child_weight': 20.0,
'n_estimators': 450,
'num_leaves': 5,
'random_state': 1,
'reg_lambda': 2.0,
'subsample': 0.99,
'subsample_freq': 6}

lgbm_clf.set_params(**lgbm_params)

lgbm_clf

输出(注意:在默认级别设置的参数已被删除,因为它们无论如何都不会显示在这里):

LGBMClassifier(colsample_bytree=0.45, learning_rate=0.057, max_depth=14,
min_child_weight=20.0, n_estimators=450, num_leaves=5,
random_state=1, reg_lambda=2.0, subsample=0.99,
subsample_freq=6)

关于python - 优化后如何将多个超参数传给LightGBM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58409692/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com