Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 시각화
- 코딩테스트
- 데이터 전처리
- matplotlib
- Python
- ML
- r
- Deep Learning Specialization
- 자격증
- pytorch
- 딥러닝
- sklearn
- ADsP
- IRIS
- 파이썬
- scikit learn
- 데이터 분석
- 통계
- 머신러닝
- 이것이 코딩테스트다
- SQL
- 이코테
- 회귀분석
- SQLD
- Google ML Bootcamp
- tableau
- 태블로
- 데이터분석준전문가
- 데이터분석
- pandas
Archives
- Today
- Total
함께하는 데이터 분석
[ML] CatBoost 본문
CatBoost
CatBoost는 많은 범주형 변수로 이루어진 데이터셋에서 성능이 매우 우수하여 categorical boost라고도 불립니다
특히 CatBoost는 다른 boosting 기반 알고리즘과 달리 categorical feature를 특별하게 처리합니다
One-Hot Encoding이나 Label Encoding 등 인코딩 과정 없이 그대로 모델에 적합시킬 수 있습니다
또 categorical feature를 그대로 모델에 넣어주면 Ordered Target Encoding을 진행합니다
Target Encoding에서 발생할 수 있는 data leakage 문제를 해결하기 위해
과거의 데이터를 이용하여 현재의 데이터를 인코딩하는 원리입니다
부스팅을 할 때 일반적인 Boosting이 아닌 Ordered Boosting을 사용합니다
먼저 train set의 row 순서를 랜덤으로 섞는 Ramdom permutation 진행하고
데이터셋의 순서를 랜덤으로 섞기 때문에 overfitting을 방지할 수 있다는 장점이 있습니다
Python 실습
import numpy as np
import warnings
warnings.filterwarnings('ignore')
from sklearn.datasets import load_iris
iris = load_iris()
X, y = iris['data'], (iris['target'] == 2).astype(np.float64)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=124)
from catboost import CatBoostClassifier
model = CatBoostClassifier(random_state=42, n_estimators=10)
model.fit(X_train, y_train)
pred = model.predict(X_test)
>>> Learning rate set to 0.284279
0: learn: 0.5586507 total: 689us remaining: 6.21ms
1: learn: 0.4513416 total: 2.03ms remaining: 8.13ms
2: learn: 0.3755346 total: 2.72ms remaining: 6.35ms
3: learn: 0.3192142 total: 3.25ms remaining: 4.88ms
4: learn: 0.2672206 total: 3.71ms remaining: 3.71ms
5: learn: 0.2242462 total: 4.15ms remaining: 2.77ms
6: learn: 0.1915199 total: 4.74ms remaining: 2.03ms
7: learn: 0.1690256 total: 5.29ms remaining: 1.32ms
8: learn: 0.1497847 total: 6.24ms remaining: 693us
9: learn: 0.1384273 total: 7.22ms remaining: 0us
from sklearn.metrics import accuracy_score
print('CatBoost Accuracy : ', round(accuracy_score(y_test, pred) * 100, 2))
>>> CatBoost Accuracy : 86.67
'데이터분석 공부 > ML | DL' 카테고리의 다른 글
[ML] 여러모델 평가지표 (1) | 2024.03.17 |
---|---|
[ML] XGBoost (0) | 2023.01.20 |
[ML] LightGBM (0) | 2023.01.20 |
[ML] 분류 모델 성능 평가 지표 (0) | 2023.01.17 |
[ML] Gradient Boosting Machine (0) | 2023.01.15 |