XGBoost
一、API详解
1.1.1 通用参数:
- booster=‘gbtree’ 使用的提升数的种类
gbtree, gblinear or dart
- silent=True: 训练过程中是否打印日志
- n_jobs=1: 并行运行的多线程数
1.1.2 提升树参数
- learning_rate=0.1: 训练的学习率,和梯度下降差不多
- max_depth=3: 树的最大深度
- gamma=0
- n_estimators=100: 要拟合的树的棵树,可以认为是训练轮数
- min_child_weight=1: 叶结点的最小权重
- subsample=1: 训练样本的抽样比率,行索引
- colsample_bytree=1: 特征的抽样比率,列索引
- reg_alpha=0: L1正则化系数
- reg_lambda=1: L2正则化系数
1.1.3 学习任务参数
- objective=‘binary:logistic’ 确定学习任务和相应的学习函数
"reg:linear" -线性回归
"reg:logistic" -逻辑回归
"binary:logistic" -二分类逻辑回归,输出概率
"binary:logitraw" -二分类逻辑回归,输出未logistic变换前的得分
"multi:softmax"
"multi:softprob"
1.1.4 控制过拟合:
- 降低模型复杂度:max_depth, min_child_weight and gamma
- 对样本随机采样:subsample, colsample_bytree
- 降低学习率,同时相应提高训练轮数
1.2 方法:
1.2.1 fit
"rmse"
"mae"
"logloss"
"error":二分类错误率,阈值是0.5
"error@t":和error类似,阈值为t
"mlogloss"
"auc"
- early_stopping_rounds=None: 提前结束轮数
- verbose=True,
- xgb_model=None,
- sample_weight_eval_set=None
1.2.2 predict(data, output_margin=False, ntree_limit=0)
返回预测类别,数据类型np.array,阈值不好控制
1.2.3 predict_proba(data, ntree_limit=0)
预测每一个数据,成为给定类别的概率
二、实例学习如何使用Xgboost
https://github.com/dmlc/xgboost/tree/master/demo
LightGBM
一、API详解
| 参数 |
XGBoost |
CatBoost |
Lightgbm |
| 模型参数 |
boosting_type=‘gbdt’(gbdt,dart,goss,rf) |
|
|
|
num_leaves=31 |
|
|
|
max_depth=-1(no limit) |
|
|
|
n_estimators=100 |
|
|
|
learning_rate=0.1 |
|
|
|
objective=(regression,binary/multiclass) |
|
|
|
class_weight=() |
|
|
|
subsample=1 训练样本采样率(行) |
|
|
|
colsample_bytree=1 训练特征采样率(列) |
|
|
|
lambda_l1=0:L1正则化系数 |
|
|
|
lambda_l2=0.0: L2正则化系数 |
|
|
|
random_state=None: 随机种子数 |
|
|
|
n_jobs=-1: 多线程数 |
|
|
|
max_bin=255 |
|
|
|
metric |
|
|
|
|
|
|
| fit |
X,y |
|
|
|
eval_set=None([(X_train, y_train), (X_valid, y_valid)]) |
|
|
|
early_stopping_rounds=None |
|
|
|
categorical_feature=‘auto’ |
|
|
|
verbose=True |
|
|
|
eval_metric=None |
|
|
| metrics |
l1/mae |
|
|
|
l2/mse(regression) |
|
|
|
l2_root/rmse |
|
|
|
binary_logloss(bi-classification) |
|
|
|
auc |
|
|
|
multi_logloss |
|
|
如何调参:
LightGBM调参笔记
LightGBM 调参方法(具体操作)
XGBoost和LightGBM的参数以及调参
参考资料:
[1] XGBoost和LightGBM的参数以及调参 |