model = lightgbm.LGBMClassifier()
hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184, ...} 我如何通过字典分配模型的超参数,以便我可以使用这些超参数来尝试模型的行为?
谢谢!
发布于 2020-01-08 04:22:48
将超参数字典传递给模型构造函数,将**添加到字典以传递每个字典项,就像lgbm期望的每个https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier的kwarg参数一样。
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,...)发布于 2020-01-08 04:52:03
sklearn BaseEstimator接口提供了get_params和set_params,用于获取和设置估计器的超参数。LightGBM是兼容的,因此您可以执行以下操作:
model = lightgbm.LGBMClassifier()
hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184}
model.set_params(**hyperparameter_dictionary)https://stackoverflow.com/questions/59635480
复制相似问题