我使用了另一种优化算法,为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)
如果我尝试获取参数,我会得到一个最佳优化参数的字典,我想再次传递给训练:
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"
lgb.LGBMClassifier().set_params(**hyper_optimized_clf_classifier.get_params())
吗? - Mischa Lisovyi