如何手动为 LGBM 分配超参数
How to manually assign hyperparameter to LGBM
model = lightgbm.LGBMClassifier()
hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184, ...}
如何通过字典分配模型的超参数,以便我可以使用此类超参数测试模型的行为?
谢谢!
将超参数字典传递给模型构造函数,将 **
添加到字典中以像 lgbm 期望的那样传递每个字典项,如 kwarg 参数 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,...)
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)
model = lightgbm.LGBMClassifier()
hyperparameter_dictionary = {'boosting_type': 'goss', 'num_leaves': 25, 'n_estimators': 184, ...}
如何通过字典分配模型的超参数,以便我可以使用此类超参数测试模型的行为?
谢谢!
将超参数字典传递给模型构造函数,将 **
添加到字典中以像 lgbm 期望的那样传递每个字典项,如 kwarg 参数 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,...)
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)