model = lightgbm.LGBMClassifier() hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184, ...}
如何使用字典设置模型的超参数?
谢谢!
回答:
将超参数字典传递给模型构造函数,在字典前添加**
,以便每个字典项像关键字参数一样传递,因为LightGBM的接口期望如此,详见https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier:
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,...)