1. 參數速查

- 使用num_leaves,因為LightGBM使用的是leaf-wise的算法,因此在調節樹的復雜程度時,使用的是num_leaves而不是max_depth。
- 大致換算關系:num_leaves = 2^(max_depth)。它的值的設置應該小於2^(max_depth),否則可能會導致過擬合。
- 對於非平衡數據集:可以param['is_unbalance']='true’
- Bagging參數:bagging_fraction+bagging_freq(必須同時設置)、feature_fraction。bagging_fraction可以使bagging的更快的運行出結果,feature_fraction設置在每次迭代中使用特征的比例。
- min_data_in_leaf:這也是一個比較重要的參數,調大它的值可以防止過擬合,它的值通常設置的比較大。
- max_bin:調小max_bin的值可以提高模型訓練速度,調大它的值和調大num_leaves起到的效果類似。

2. 回歸
3. 分類
先舉個例子:
from sklearn.model_selection import train_test_split, StratifiedKFold
import lightgbm as lgb
# reg_alpha:L1正則,reg_lambda:L2正則
clf = lgb.LGBMClassifier(
boosting_type = 'gbdt', num_leaves = 64, reg_alpha = 5, reg_lambda = 5,
n_estimators = 4053, objective = 'binary',
subsample = 0.7, colsample_bytree = 0.7, subsample_freq = 1,
learning_rate = 0.05, random_state = 8012, n_jobs = -1)
clf.fit(train_data, labels, eval_set = [(train_data, labels)], verbose = 50)
test_result = clf.predict_proba(test_data)
test_data = all_data[all_data.label == -1].drop('label', axis = 1).reset_index(drop = True)
test_data['label'] = test_result[:, 1]
test_data['label'] = test_data.label.apply(lambda x:1 if x >= 0.36 else 0)
參考文獻:
【1】LightGBM參數介紹
