Datawhale干货
作者:阿水,北京航空航天大学,Datawhale成员
LightGBM是基于XGBoost的一款可以快速并行的树模型框架,内部集成了多种集成学习思路,在代码实现上对XGBoost的节点划分进行了改进,内存占用更低训练速度更快。
LightGBM官网:https://lightgbm.readthedocs.io/en/latest/
参数介绍:https://lightgbm.readthedocs.io/en/latest/Parameters.html
本文内容如下,原始代码获取方式见文末。
- 1 安装方法
- 2 调用方法
- 2.1 定义数据集
- 2.2 模型训练
- 2.3 模型保存与加载
- 2.4 查看特征重要性
- 2.5 继续训练
- 2.6 动态调整模型超参数
- 2.7 自定义损失函数
- 3 调参方法
人工调参
网格搜索
贝叶斯优化
1 安装方法
LightGBM的安装非常简单,在Linux下很方便的就可以开启GPU训练。可以优先选用从pip安装,如果失败再从源码安装。
- 安装方法:从源码安装
- 安装方法:pip安装
2 调用方法
在Python语言中LightGBM提供了两种调用方式,分为为原生的API和Scikit-learn API,两种方式都可以完成训练和验证。当然原生的API更加灵活,看个人习惯来进行选择。
2.1 定义数据集
2.2 模型训练
2.3 模型保存与加载
2.4 查看特征重要性
2.5 继续训练
2.6 动态调整模型超参数
2.7 自定义损失函数
2.8 调参方法
人工调参
For Faster Speed
- Use bagging by setting
bagging_fraction
and bagging_freq
- Use feature sub-sampling by setting
feature_fraction
- Use small
max_bin
- Use
save_binary
to speed up data loading in future learning - Use parallel learning, refer to
Parallel Learning Guide <./Parallel-Learning-Guide.rst>
__
For Better Accuracy
- Use large
max_bin
(may be slower) - Use small
learning_rate
with large num_iterations
- Use large
num_leaves
(may cause over-fitting) - Use bigger training data
- Try
dart
Deal with Over-fitting
- Use small
max_bin
- Use small
num_leaves
- Use
min_data_in_leaf
and min_sum_hessian_in_leaf
- Use bagging by set
bagging_fraction
and bagging_freq
- Use feature sub-sampling by set
feature_fraction
- Use bigger training data
- Try
lambda_l1
, lambda_l2
and min_gain_to_split
for regularization - Try
max_depth
to avoid growing deep tree - Try
extra_trees
- Try increasing
path_smooth
网格搜索
贝叶斯优化
本文代码,可以在后台回复【lgb】,下载本文的代码Notebook!
“干货学习,点赞三连↓