[ ML ] Kaggle에 적용해보는 XGBoost

peter_yun
3 min readMay 8, 2017

--

what is xgboost, how to tune parameters, kaggle tutorial

출처 : https://www.hackerearth.com/practice/machine-learning/machine-learning-algorithms/beginners-tutorial-on-xgboost-parameter-tuning-r/tutorial/

아직까지 100% 이해가 잘 안가지만 위 포스팅을 통해 조금이나마 내가 이해한 내용을 남겨보려 한다. 남겨두면 훗날 도움이 될 것이라고 생각한다.

Introduction

  • Random forest의 연장선 상에 있음. Random forest는 resampled data를 기반으로 모델들을 만들기 때문에 variance를 낮출 수 있는 장점이 있음
  • boosting algorithm이 기반이 됨
  • 최근에 kaggle 유저들에게 큰 인기를 끌고 있음

What is XGBoost?

  • XGboost는 Extreme Gradient Boosting의 약자
  • Gradient boosting 알고리즘을 핵심으로 함
  • 주로 Supervised ML problems에 활용

주요 특징

  • Parallel Computing
  • Regularization :
    linear나 tree based model에서 과적합을 피하는 방식 중 하나이다.
  • Enabled Cross Validation :
    CV function이 내장되어 있다.
  • Missing Values :
    결측치를 내부적으로 처리해준다. 실제로 kaggle에 적용해보는 과정에서 정말 편리하였다.
  • Flexbility :
    objective function은 모델의 성능을 평가하는데 활용되는데 xgboost는 사용자 정의 objective function과 evaluation metrics를 사용할 수 있도록 해준다.
  • Availability :
    python, R을 포함한 다양한 언어로 활용이 가능하다.
  • Save and Reload
  • Tree Pruning :
    일반적인 gradient boosting에서는 tree pruning 과정이 negative loss가 발생하면 멈추게 된다. 하지만 xgboost는 max_depth까지 진행한 뒤 loss function 에서의 개선이 일정 threshold에 못미칠 경우까지 역방향으로 pruning과정을 진행한다.

How doex XGboost work?

Boosting algotithm

  • XGBoost는 boosting algorithm의 가족이라고 할 수 있다.
  • boosting algorithm은 weak learners들을 strong learner로 변환한다.
  • Boosting은 sequential process로 이전 tree로 부터 얻은 정보를 다음 tree를 생성하는데 활용하기 때문이다.

XGBoost

xgboost는 regression과 classification에 모두 활용될 수 있다.

  • Regression Problem : booster = gbtree와 gblinear 파라미터 모두 가능 / linear model에서는 regularization과 gradient descent로 최적화
  • Classification Problem : booster = gbtree 파라미터를 사용 / 다음 tree는 이전 tree에서 오분류된 지점에 더 높은 가중치를 줌

Tuning Parameters in XGBoost

이 글의 필자는 parameter와 관련해서 아래와 같이 말했다.

“ using xgboost without parameter tuning is like driving a car without changing its gears; you can never up your speed ”

https://www.hackerearth.com/practice/machine-learning/machine-learning-algorithms/beginners-tutorial-on-xgboost-parameter-tuning-r/tutorial/

주요 Parameters

  • nround : maximum number of iteration, similar to number of trees
  • eta : controls learning rate, lower eta -> slower computation
  • gamma : controls regularization
  • max_depth : depth of the tree, Larger depth -> complex model -> higher chance of over fitting , should be tuned using CV
  • min_child_weight : minimum number of instances required in a child node(?), simply it blocks the potential feature interactions to prevent over fitting
  • subsample : controls the number of samples supplied to a tree
  • colsample_bytree : number of features supplied to a tree
  • objective : methods for loss function
  • eval_metric : methods for evaluation, RMSE/error 등

Kaggle Tutorials

https://www.kaggle.com/c/prudential-life-insurance-assessment

현재 스터디원들과 참여 중인 문제는 가입상품, 나이, BMI, 보험이력, 고용정보 등 Prudential 보험사의 데이터를 기반으로 고객들을 위험군에 따라서 1~8등급으로 분류하는 문제이다.

  • 앞으로 확인해봐야할 것 : regularization, loss function, random forest

--

--