LightGBM은 리프 중심 트리 분할을 사용함(비대칭 트리임)
- 트리의 균형을 맞추지 않고 최대손실 값을 가지는 리프 노드를 계속 분할
- 균형 트리 분할 보다 예측 오류 손실을 줄일 수 있다는 사상
n_estimators(Default : 100) : 반복 수행하려는 트리의 개수 지정
(= XGBoost > n_estimators)
learning_rate(Default : 0.1) : 부스팅 스텝을 반복 수행할 때의 학습률
(n_estimators, learning_rate는 서로 상반된 관계)
max_depth(Default : -1) : 트리 기반 max_depth와 같음
min_data_in_leaf(Default : 20) : 각 리프노드에 있어야 하는 최소 개수
num_leavse(Default : 31) : 하나의 트리가 가질 수 있는 최대 리프 개수
boosting(Default : gbdt) : .부스팅의 트리 생성 알고리즘
bagging_fraction(Default) : 데이터를 샘플링 하는 비율임
feature_fraction(Default) : 개별 트리 학습시 무작위로 선택하는 피처 비율
lambda_l2(Default : 0.0) : 가중치에 페널티를 부여하여 과적합을 줄임(가중치 제곱 합)
lambda_l1(Default : 0.0) : L2랑 마찬가지 (가중치 절대값 합)
파라미터 튜닝의 경우 min_child_samples, max_depth를 조절함
lgbm_wrapper = LGBMClassifier(n_estimators=400, learning_rate=0.05)
evals = [(X_tr, y_tr), (X_val, y_val)]
lgbm_wrapper.fit(X_tr, y_tr, early_stopping_rounds=50, eval_metric="logloss", eval_set=evals, verbose=True)
preds = lgbm_wrapper.predict(X_test)
pred_proba = lgbm_wrapper.predict_proba(X_test)[:, 1]
get_clf_eval(y_test, preds, pred_proba)
from lightgbm import plot_importance
import matplotlib.pyplot as plt
%matplotlib inline
fig, ax = plt.subplots(figsize=(10, 12))
plot_importance(lgbm_wrapper, ax=ax)
plt.savefig('lightgbm_feature_importance.tif', format='tif', dpi=300, bbox_inches='tight')