首页 > 解决方案 > How to manually assign hyperparameter to LGBM

问题描述

model = lightgbm.LGBMClassifier()  
hyperparameter_dictionary = {'boosting_type': 'goss',   'num_leaves': 25, 'n_estimators': 184, ...}  

How do I assign the model's hyperparameters by the dictionary, so that I can try out the model's behavior with such hyperparameters?

Thanks!

标签: pythonmachine-learningscikit-learnhyperparameterslightgbm

解决方案


将超参数字典传递给模型构造函数,添加**到 dict 以传递每个 dict 项,如 lgbm 期望的 kwarg 参数https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm .LGBM分类器

hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184}
model = lightgbm.LGBMClassifier(**hyperparameter_dictionary)

测试:

print(model)

LGBMClassifier(boosting_type='goss', ... n_estimators=184, n_jobs=-1, num_leaves=25,...)

推荐阅读