LightGBM

XGBoost와 성능의 차이는 별반 없으나 시간이 덜 소모됨

적은 데이터 세트에서 활용 할 경우 과적합의 문제가 야기됨

LightGBM은 리프 중심 트리 분할을 사용함(비대칭 트리임)

  • 트리의 균형을 맞추지 않고 최대손실 값을 가지는 리프 노드를 계속 분할
  • 균형 트리 분할 보다 예측 오류 손실을 줄일 수 있다는 사상

종류

  • LGBMClassifier : 분류
  • LGBMRegressor : 회귀

Parameter

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를 조절함


예제

model

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)

중요 feature 시각화

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')

0개의 댓글