250x250
Link
나의 GitHub Contribution 그래프
Loading data ...
Notice
Recent Posts
Recent Comments
관리 메뉴

Data Science LAB

[Python] XGBoost 본문

adp 실기/알고리즘 이론

[Python] XGBoost

ㅅ ㅜ ㅔ ㅇ 2022. 8. 19. 15:43
728x90

XGBoost

여러개의 의사결정나무를 조합하여 사용하는 앙상블 알고리즘으로 GBM에 기반하고 있지만, 느린 수행 시간 및 과적합 규제 부재 등의 문제를 해결하였다. 특히 병렬 CPU환경에서 병렬 학습이 가능해 기존 GBM보다 빠르게 학습 가능하다.

 

<장점>

  • 뛰어난 예측 성능
  • GBM 대비 빠른 수행 시간
  • 과적합 규제
  • 나무 가지치기 : 가지치기로 긍정 이득이 더 이상 없는 분할은 분할 수를 더 줄이는 장점
  • 자체 내장된 교차 검증
  • 결손값 자체 처리

 

XGBBoost(max_depth, objective, eval_metric, learning_rate, subsample)

 

XGBClassifier

xgbc = XGBClassifier(random_state=42)
xgbc.fit(X1_train, y1_train)
pred = xgbc.predict(X1_test)

acc = accuracy_score(y1_test, pred)
acc

# 0.956140350877193
plt.figure(figsize=(10,6))
sns.barplot(y=X1.columns.tolist(), x=xgbc.feature_importances_, edgecolor=(0,0,0))
plt.show()

 

 

XGBRegressor

xgbr = XGBRegressor(random_state = 42)
xgbr.fit(X2_train, y2_train)
pred = xgbr.predict(X2_test)

mean_squared_error(y2_test, pred)
# 6.747557632786527

 

728x90

'adp 실기 > 알고리즘 이론' 카테고리의 다른 글

[Python] RandomForest  (0) 2022.08.18
[Python] DecisionTree (의사결정나무)  (0) 2022.08.17
[Python] 서포트벡터머신(SVM)  (0) 2022.08.16
Comments