๋ชฉํ
- ํน์ฑ ์ค์๋ ๊ณ์ฐ ๋ฐฉ๋ฒ๋ค ์ดํด ๋ฐ ๋ชจ๋ธ ํด์์ ํ์ฉ
- Boosting์ ๋ํ ์ดํด ๋ฐ ๋ชจ๋ธ ํ์ต
ํน์ฑ ์ค์๋
- Feature Importance(Mean Decrease Impurity ; MDI)
- sklearn ํธ๋ฆฌ ๊ธฐ๋ฐ ๋ถ๋ฅ๊ธฐ์์ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉ๋๋ ๊ณ์ฐ ๋ฐฉ๋ฒ์ผ๋ก ๊ฐ๊ฐ์ ํน์ฑ์ ๋ชจ๋ ํธ๋ฆฌ์ ๋ํด ํ๊ท ๋ถ์๋ ๊ฐ์(MDI)๋ฅผ ๊ณ์ฐํ ๊ฐ์ ๋๋ค.
๋ถ์๋ ๊ฐ์(impurity decrease)๋ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐํฉ๋๋ค:
$$\displaystyle \frac{N_t}{N}$ * (impurity - \displaystyle\frac{N_{tR}}{N_t} * Rightimpurity - \displaystyle\frac{N_{tL}}{N_t}$ * Leftimpurity)$$
$$N: ์ ์ฒด ๊ด์ธก์น ์, N_t: ํ์ฌ ๋ ธ๋ t์ ์กด์ฌํ๋ ๊ด์ธก์น ์$$
$$N_{tL}, N_{tR}: ๋ ธ๋ t ์ผ์ชฝ(L)/์ค๋ฅธ์ชฝ(R) ์์๋ ธ๋์ ์กด์ฌํ๋ ๊ด์ธก์น ์$$
$$๋ง์ฝ SampleWeight๊ฐ ์ฃผ์ด์ง๋ค๋ฉด, N, N_t, N_{tR}, N_{tL}๋ ๊ฐ์คํฉ์ ํฉ๋๋ค.$$
- ์ฃผ์์ : MDI Feature Importance๋ high cardinality features์ ๋ํด ๊ณผํ๊ฒ ๋์ ๊ฐ์ด ๋์ค๋ ๊ฒฝํฅ์ด ์์ต๋๋ค.
๋ฒ์ฃผ๊ฐ ๋ง์์๋ก ๊ฐ ๋ ธ๋์ ๊ธฐ์ฌํ ํ๋ฅ ์ด ๋๊ธฐ ๋๋ฌธ์ ๋๋ค.(ํนํ max_depth์ ์ ํ์ ๋์ง ์๋๋ค๋ฉด ๋์ฑ์ด ๊ณผํ๊ฒ ์ธก์ ๋ฉ๋๋ค.)
์์)
# ํน์ฑ ์ค์๋
rf = pipe.named_steps['randomforestclassifier']
importances = pd.Series(rf.feature_importances_, X_train.columns)
%matplotlib inline
import matplotlib.pyplot as plt
n = 20
plt.figure(figsize=(10,n/2))
plt.title(f'Top {n} features')
importances.sort_values()[-n:].plot.barh();
- Drop-Column Importance
- ํน์ฑ๋ง๋ค ํ๋์ฉ drop ์ ๊ณผ ํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ธํ ํ๊ณ ๋ชจ๋ธ์ fittingํ์ฌ score๋ฅผ ๋น๊ตํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
- ์ด๋ก ์ ์ผ๋ก ํน์ฑ์ ์ค์๋๋ฅผ ์ธก์ ํ๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ด์ง๋ง, ๊ทธ ๊ณผ์ ์ด ๋ค์ ๋ฒ๊ฑฐ๋กญ๋ค๋ ๋จ์ ์ด ์์ต๋๋ค.
์์)
column = 'opinion_seas_risk' # ์ค์๋๋ฅผ ์ธก์ ํด๋ณด๊ณ ์ถ์ ํน์ฑ
# opinion_h1n1_risk ์์ด fit
pipe = make_pipeline(
OrdinalEncoder(),
SimpleImputer(),
RandomForestClassifier(n_estimators=100, random_state=2, n_jobs=-1)
)
pipe.fit(X_train.drop(columns=column), y_train)
score_without = pipe.score(X_val.drop(columns=column), y_val)
print(f'๊ฒ์ฆ ์ ํ๋ ({column} ์ ์ธ): {score_without}')
# opinion_h1n1_risk ํฌํจ ํ ๋ค์ ํ์ต
pipe = make_pipeline(
OrdinalEncoder(),
SimpleImputer(),
RandomForestClassifier(n_estimators=100, random_state=2, n_jobs=-1)
)
pipe.fit(X_train, y_train)
score_with = pipe.score(X_val, y_val)
print(f'๊ฒ์ฆ ์ ํ๋ ({column} ํฌํจ): {score_with}')
# opinion_h1n1_risk ํฌํจ ์ ํ ์ ํ๋ ์ฐจ์ด๋ฅผ ๊ณ์ฐํฉ๋๋ค
print(f'{column}์ Drop-Column ์ค์๋: {score_with - score_without}')
- Permutation Importance(Mean Decrease Accuracy ; MDA) ; ์์ด ์ค์๋
- ๊ธฐ๋ณธ ํน์ฑ ์ค์๋(MDI)์ Drop-Column ์ค์๋์ ์ค๊ฐ์ ์์นํ๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค.
- ๊ด์ฌ์๋ ํน์ฑ์๋ง ๋ฌด์์๋ก ๋ ธ์ด์ฆ๋ฅผ ์ฃผ๊ณ ์์ธกํ์์ ๋ ์ฑ๋ฅ ํ๊ฐ์งํ(accuracy, F1, R2 ๋ฑ)๊ฐ ๊ฐ์ํ๋ ์ ๋๋ฅผ ์ธก์ ํฉ๋๋ค.
- Drop-Column ์ค์๋์ ๋ค๋ฅด๊ฒ ๊ฒ์ฆ๋ฐ์ดํฐ์์ ๊ฐ ํน์ฑ์ ์ ๊ฑฐํ์ง ์๊ณ ํน์ฑ๊ฐ์ ๋ฌด์์๋ก ๋
ธ์ด์ฆ๋ฅผ ์ฃผ์ด ๊ธฐ์กด ์ ๋ณด๋ฅผ ์ ๊ฑฐํ๊ณ
์ฑ๋ฅ์ ์ธก์ ํ ์ ์์ต๋๋ค. ๋ ธ์ด์ฆ๋ฅผ ์ฃผ๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ํด๋น ํน์ฑ๊ฐ๋ค์ ์ํ ๋ด์์ ์๋ ๊ฒ(shuffle, permutation)์ ๋๋ค.
์์1)
# ๋ณ๊ฒฝ ํ ํน์ฑ์ ์ ํํฉ๋๋ค
feature = 'opinion_seas_risk'
X_val[feature].head()
# ํน์ฑ์ ๋ถํฌ๋ฅผ ํ์ธํฉ๋๋ค
X_val[feature].value_counts()
# ํน์ฑ์ ๊ฐ์ ๋ฌด์์๋ก ์์ต๋๋ค
X_val_permuted = X_val.copy()
X_val_permuted[feature] = np.random.RandomState(seed=7).permutation(X_val_permuted[feature])
# ํน์ฑ ๊ฐ์ ์์๊ฐ ๋ค๋ฐ๋ ๊ฒ์ ํ์ธํฉ๋๋ค
X_val_permuted[feature].head()
# ์นดํ
๊ณ ๋ฆฌ๋ค์ ๋ถํฌ๋ ๋ฐ๋์ง๋ ์์์์ ํ์ธํฉ๋๋ค
X_val_permuted[feature].value_counts()
# ์์ด ์ค์๋ ๊ฐ์ ์ป์ต๋๋ค. (์ฌํ์ต์ด ํ์ ์์ต๋๋ค!)
score_permuted = pipe.score(X_val_permuted, y_val)
print(f'๊ฒ์ฆ ์ ํ๋ ({feature}): {score_with}')
print(f'๊ฒ์ฆ ์ ํ๋ (permuted "{feature}"): {score_permuted}')
print(f'์์ด ์ค์๋: {score_with - score_permuted}')
์์2) eli5 ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉ
! pip install eli5
import eli5
from eli5.sklearn import PermutationImportance
permuter = PermutationImportance(
model, # ์ฌ๊ธฐ์ model์ ๋ฏธ๋ฆฌ train set์ ๋ํด fit์ด ๋์ด์์ด์ผํฉ๋๋ค.
scoring='accuracy', # ๋ค๋ฅธ score๋ค๋ ๊ฐ๋ฅ
n_iter=5, # ๋ค๋ฅธ random seed๋ฅผ ์ฌ์ฉํด์ 5๋ฒ ๋ฐ๋ณตํฉ๋๋ค.
random_state=2
)
permuter.fit(X_val, y_val)
permuter.feature_importances_
์ถ๊ฐ) eli5.show_weights
# ํน์ฑ๋ณ score ํ์ธ
eli5.show_weights(
permuter,
top=None, # top n ์ง์ ๊ฐ๋ฅ, None ์ผ ๊ฒฝ์ฐ ๋ชจ๋ ํน์ฑ
feature_names=feature_names # list ํ์์ผ๋ก ๋ฃ์ด์ผ ํฉ๋๋ค
)
Permutation Importance๋ฅผ ์ฌ์ฉํ์ฌ ํน์ฑ์ ์ ํํ๋ ํ
minimum_importance = 0.001
mask = permuter.feature_importances_ > minimum_importance
features = X_train.columns[mask] # True์ ํด๋นํ๋ column๋ง ๊ฐ์ ธ์จ๋ค.
X_train_selected = X_train[features]
X_val_selected = X_val[features]
- ์์ ๊ฐ์ด ํน์ ๊ฐ ์ด์์ ์ค์๋๋ฅผ ๊ฐ์ง ํน์ฑ๋ค๋ง ๋ฐ๋ก ์ ํํ์ฌ ๋ชจ๋ธ์ ๋ค์ fittingํ์ฌ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ์ผ๋ฐ์ ์ผ๋ก importance๊ฐ ๋งค์ฐ ์์ ํน์ฑ๋ค์ ์ ๊ฑฐํด๋ score์ ํฐ ์ํฅ์ด ์์ผ๋ฉฐ ํน์ฑ ๊ฐฏ์๊ฐ ์ ์ผ๋ฏ๋ก ๋ ํจ์จ์ ์ ๋๋ค.
์ถ๊ฐ) ์ค์๋์ ํ์คํธ์ฐจ๊น์ง ๊ณ ๋ คํ๋ ๊ฒฝ์ฐ
permuter.feature_importances_ - permuter.feature_importances_std_ > 0
# ์์ด ์ค์๋์ ํ๊ท ๊ฐ์๊ฐ๊ณผ ๊ทธ ํ์คํธ์ฐจ์ ์ฐจ๊ฐ ์์์ธ ํน์ง๋ค์ ํ์ธํ ์ ์์ต๋๋ค.
# ํ์คํธ์ฐจ๊น์ง ๊ณ ๋ คํด์ ์์, ์ฆ ์ธ์ ๋ ์์๊ฐ
# ์์ ์ค์๋์์ 8๊ฐ๊ฐ feature importance๋ 0.001๋ณด๋ค ํฐ ๊ฒฝ์ฐ์ง๋ง ํ์คํธ์ฐจ๊น์ง ๊ณ ๋ คํ๋ฉด 7๊ฐ๋ง ์์์ ํด๋นํฉ๋๋ค. ('education_comp'๊ฐ ์ ์ธ๋จ)
Boosting
- ๋ฐฐ๊น
(๋๋คํฌ๋ ์คํธ)์ ๊ฒฝ์ฐ, ๋
๋ฆฝ์ ์ธ ์ฌ๋ฌ ํธ๋ฆฌ๋ค์ ๋ง๋ค์ง๋ง
๋ถ์คํ ์ ๋ง๋ค์ด์ง๋ ํธ๋ฆฌ๊ฐ ์ด์ ์ ๋ง๋ค์ด์ง ํธ๋ฆฌ์ ์ํฅ์ ๋ฐ์ต๋๋ค. - ๋ฐฐ๊น
(๋๋คํฌ๋ ์คํธ)์ ์ฅ์ ์
ํ์ดํผํ๋ผ๋ฏธํฐ์ ์๋์ ์ผ๋ก ๋ ๋ฏผ๊ฐํ ๊ฒ
์ธ๋ฐ, ๋ถ์คํ (๊ทธ๋๋์ธํธ ๋ถ์คํ )์ ๊ฒฝ์ฐ ํ์ดํผํ๋ผ๋ฏธํฐ
์ธํ ์ ๋ฐ๋ผ ๋ฐฐ๊น ๋ณด๋ค ๋ ์ข์ ์์ธก ์ฑ๋ฅ์ ๋ณด์ฌ์ค ์ ์์ต๋๋ค. - ํธ๋ฆฌ ๊ธฐ๋ฐ ๋ชจ๋ธ์ non-linear, non-monotonic ๊ด๊ณ, ํน์ฑ๊ฐ ์ํธ์์ฉ์ด ์กด์ฌํ๋ ๋ฐ์ดํฐ ํ์ต์ ์ ์ฉํ๊ธฐ ์ข์ต๋๋ค.
- AdaBoost
- ๋ชจ๋ ์ํ์ ๋์ผํ ๊ฐ์ค์น๋ฅผ ์์์ผ๋ก ๊ฐ ํธ๋ฆฌ(weak learners)๊ฐ ๋ง๋ค์ด์ง ๋ ์๋ชป ๋ถ๋ฅ๋๋ ๊ด์ธก์น(์ํ)์ ๊ฐ์ค์น๋ฅผ ์ค๋๋ค.
- ๋ค์ ํธ๋ฆฌ๊ฐ ๋ง๋ค์ด์ง ๋ ์ด์ ํธ๋ฆฌ์์ ์๋ชป ๋ถ๋ฅ๋ ์ํ์ ๋ ๋ง์ ๊ฐ์ค์น๋ฅผ ๋ฐ์ ๋ ๋ง์ด ์ํ๋ง๋์ด ๊ทธ ์ํ์
๋ ์ง์คํ ์ ์๊ฒ ๋ฉ๋๋ค.
Step 0. ๋ชจ๋ ๊ด์ธก์น์ ๋ํด ๊ฐ์ค์น๋ฅผ ๋์ผํ๊ฒ ์ค์ ํฉ๋๋ค.
Step 1. ๊ด์ธก์น๋ฅผ ๋ณต์์ถ์ถ ํ์ฌ ์ฝํ ํ์ต๊ธฐ Dn์ ํ์ตํ๊ณ +, - ๋ถ๋ฅ ํฉ๋๋ค.
Step 2. ์๋ชป ๋ถ๋ฅ๋ ๊ด์ธก์น์ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํด ๋ค์ ๊ณผ์ ์์ ์ํ๋ง์ด ์๋๋๋ก ํฉ๋๋ค.
Step 3. Step 1~2 ๊ณผ์ ์ nํ ๋ฐ๋ณต(n = 3) ํฉ๋๋ค.
Step 4. ๋ถ๋ฅ๊ธฐ๋ค(D1, D2, D3)์ ๊ฒฐํฉํ์ฌ ์ต์ข ์์ธก์ ์ํํฉ๋๋ค.
- ์ต์ข
ํ์ต๊ธฐ(H(x))๋ ์ฝํ ํ์ต๊ธฐ๋ค(h_t)์ ๊ฐ์ค(α)ํฉ์ผ๋ก ๋ง๋ค์ด์ง๋๋ค. α๋ Say(๊ฒฐ์ ๋ ฅ)์ ์๋ฏธํฉ๋๋ค. ๊ฒฐ์ ๋ ฅ์ด ํด์๋ก ๋ถ๋ฅ๊ธฐ
์ ์ฑ๋ฅ์ด ์ข๋ค๋ ๋ป์ ๋๋ค.
์ถ๊ฐ) AdaBoost๋ node 1๊ฐ์ leaf 2๊ฐ์ธ Stump๋ฅผ ๊ธฐ๋ณธ ๋ชจ๋ธ๋ก ์ฌ์ฉํฉ๋๋ค. ์ฌ๋ฌ Stump์ ์กฐํฉ์ ๋๋ค.
- Gradient Boost
- AdaBoost์ ์ ์ฌํ์ง๋ง ๋น์ฉํจ์(Loss function)์ ์ต์ ํํ๋ ๋ฐฉ๋ฒ์ ์์ด ์ฐจ์ด๊ฐ ์์ต๋๋ค.
- AdaBoost๊ฐ ์ํ์ ๊ฐ์ค์น๋ฅผ ๋์ผํ๊ฒ ์ฃผ๊ณ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ ๋์ Gradient Boost์์๋ ์์ฐจ(residual)์ ํ์ตํ๋๋ก ํฉ๋๋ค.
์์ฐจ๊ฐ ๋ ํฐ ๋ฐ์ดํฐ๋ฅผ ๋ ํ์ตํ๋๋ก ๋ง๋๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค. - ํ๊ท์ ๋ถ๋ฅ ๋ฌธ์ ๋ชจ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ผ์ด๋ธ๋ฌ๋ฆฌ
- ๊ธฐ๋ณธ์ ์ผ๋ก sklearn.ensemble์ AdaBoost์ GradientBoost๊ฐ ๊ตฌํ๋์ด์์ง๋ง ๋ถ์คํ ์ ๋ณดํต ๋ค๋ฅธ ๋ ์ข์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํฉ๋๋ค.
- XGBoost : ๊ฒฐ์ธก๊ฐ์ ์์ฉ, monotonic constrains๋ฅผ ๊ฐ์ ํ ์ ์์ต๋๋ค.
import xgboost
from xgboost import XGBClassifier
- LightGBM : ๊ฒฐ์ธก๊ฐ์ ์์ฉ, monotonic constrains๋ฅผ ๊ฐ์ ํ ์ ์์ต๋๋ค.
import lightgbm
from lightgbm import LGBMClassifier
- CatBoost : ๊ฒฐ์ธก๊ฐ์ ์์ฉ, categorical features๋ฅผ ์ ์ฒ๋ฆฌ ์์ด ์ฌ์ฉํ ์ ์์ต๋๋ค.
!pip install catboost # ๊ตฌ๊ธ ์ฝ๋ฉ ์กฐ๊ฑด์์ ๋ฐ๋ก ์ค์น๋ฅผ ํด์ฃผ์ด์ผํฉ๋๋ค.
import catboost
from catboost import CatBoostClassifier
์ฐธ๊ณ : monotonic constrains
- monotonic constraints ํจ๊ณผ, ๋จ์กฐ์ฆ๊ฐํด์ผ ํ๋ ํน์ฑ์ด ์ค๋ฅ๋ก ๋น๋จ์กฐ ์ฆ๊ฐํ ๋ ๋ณ์๋ง๋ค ์ ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
- ๊ฐ์ด ์์ ๋ถ๋ถ์ ๋ํด์ ๋ฐ์ดํฐ๊ฐ ์์ด์ ๊ฐ์ํ๋ ๊ฑฐ์ฒ๋ผ ๋์ค์ง๋ง ์ฐ๋ฆฌ๊ฐ ์ด ํน์ฑ์ ๋จ์กฐ์ฆ๊ฐ(์ฐ์ํฅ)ํ๋
๊ฑธ ์๊ณ ์๋ค๋ฉด ์ด ๋ถ๋ถ์ ๋ณด์ ํด์ค ์ ์์ต๋๋ค.
Early Stopping
- ๋ฐฐ๊น
๊ณผ ๋ค๋ฅด๊ฒ ๋ถ์คํ
์ ๊ทธ ์์ ๊ธฐ๋ณธ๋ชจ๋ธ์ธ tree๋ฅผ ์์ฐจ์ ์ผ๋ก ํ์ตํ๊ฒ ๋ฉ๋๋ค. ๋ฐ๋ผ์ ๋ชจ๋ n_estimators(tree model์ ์)
๋ฅผ ํ์ตํ ๊ฒ ์์ด ์ผ์ ๊ธฐ์ค์น๊น์ง๋ง ์ฑ์ฐ๋ฉด ํ์ตํ์ง ์๊ฒ ์กฐ์ ํ ์ ์์ต๋๋ค. - GridSearchCV, RandomizedSearchCV ํน์ ๋ฐ๋ณต๋ฌธ์ผ๋ก n_estimators์ ์ต์ ์ ๊ฐ์ ์ฐพ์ผ๋ ค๋ฉด ๋๋ฌด ๋ง์ ๋ฐ๋ณต์ด ํ์ํฉ๋๋ค.
๋ํ, ๋ค๋ฅธ ํ์ดํผํ๋ผ๋ฏธํฐ์์ ์กฐํฉ๊น์ง ๊ฒฝ์ฐ์ ์๋ฅผ ์๊ฐํ๋ฉด ํ์ต ํ์๊ฐ ๋น์ฝ์ ์ผ๋ก ์ฆ๊ฐํฉ๋๋ค.
์ด๋ด ๋, ๋ถ์คํ ์ ๊ฒฝ์ฐ Early Stopping์ ํ์ฉํ์ฌ ์์ฃผ ํจ๊ณผ์ ์ผ๋ก n_estimators๋ฅผ ์ต์ ํํ ์ ์์ต๋๋ค.
์์)
encoder = OrdinalEncoder()
X_train_encoded = encoder.fit_transform(X_train) # ํ์ต๋ฐ์ดํฐ
X_val_encoded = encoder.transform(X_val) # ๊ฒ์ฆ๋ฐ์ดํฐ
model = XGBClassifier(
n_estimators=1000, # <= 1000 ํธ๋ฆฌ๋ก ์ค์ ํ์ง๋ง, early stopping ์ ๋ฐ๋ผ ์กฐ์ ๋ฉ๋๋ค.
max_depth=7, # default=3, high cardinality ํน์ฑ์ ์ํด ๊ธฐ๋ณธ๋ณด๋ค ๋์ฌ ๋ณด์์ต๋๋ค.
learning_rate=0.2,
# scale_pos_weight=ratio, # imbalance ๋ฐ์ดํฐ ์ผ ๊ฒฝ์ฐ ๋น์จ์ ์ ์ฉํฉ๋๋ค.
n_jobs=-1
)
eval_set = [(X_train_encoded, y_train),
(X_val_encoded, y_val)]
model.fit(X_train_encoded, y_train,
eval_set=eval_set,
eval_metric='error', # #(wrong cases)/#(all cases)
early_stopping_rounds=50
) # 50 rounds ๋์ ์ค์ฝ์ด์ ๊ฐ์ ์ด ์์ผ๋ฉด ๋ฉ์ถค # ์ค์ฝ์ด๊ฐ ์ต๊ณ ์ ์ ์ฐ๊ณ ์ดํ 50๊ฐ๋ฅผ ๋ ํด๋ณด๋ ๊ฒ
# ์๋ ๊ฒฐ๊ณผ์์ validation_0_error๊ฐ train set์ ๋ํ ๊ฒ/ validation_1_error๊ฐ val set์ ๋ํ ๊ฒ
# ์ต์ ์ n_estimators๋ก model์ด fitting ๋ฉ๋๋ค.
์ฐธ๊ณ )
์์ scale_pos_weight
๋ ์๋์ ๊ฐ์ด ์ค ์ ์์ต๋๋ค.
- 1์ ํด๋นํ๋ ์ํ์ ๊ฐ์ค์ ์ฃผ๋ ๊ฒ์ด๋ 'ํ๊ฒ๊ฐ(0) ๊ฐฏ์ / ํ๊ฒ๊ฐ(1) ๊ฐฏ์' ๋ฅผ positive์ ๊ณฑํ๋ฉด ๋์ ๋น์จ์ด 1:1์ด ๋ฉ๋๋ค.
์ฐธ๊ณ 2)
๋ค์๊ณผ ๊ฐ์ด ์ผ์ ์(์์์์ 35) ์ดํ๋ก๋ ๊ฒ์ฆ ๋ฐ์ดํฐ์ ๋ํ error๊ฐ ๋ ๋จ์ด์ง์ง ์๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
results = model.evals_result()
train_error = results['validation_0']['error']
val_error = results['validation_1']['error']
epoch = range(1, len(train_error)+1)
plt.plot(epoch, train_error, label='Train')
plt.plot(epoch, val_error, label='Validation')
plt.ylabel('Classification Error')
plt.xlabel('Model Complexity (n_estimators)')
plt.ylim((0.15, 0.25)) # Zoom in
plt.legend();
์ฐธ๊ณ
ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋
Random Forest
- max_depth (๋์๊ฐ์์ ๊ฐ์์ํค๋ฉฐ ํ๋, ๋๋ฌด ๊น์ด์ง๋ฉด ๊ณผ์ ํฉ)
- n_estimators (์ ์๊ฒฝ์ฐ ๊ณผ์์ ํฉ, ๋์๊ฒฝ์ฐ ๊ธด ํ์ต์๊ฐ)
- min_samples_leaf (๊ณผ์ ํฉ์ผ๊ฒฝ์ฐ ๋์)
- max_features (์ค์ผ ์๋ก ๋ค์ํ ํธ๋ฆฌ์์ฑ, ๋์ด๋ฉด ๊ฐ์ ํน์ฑ์ ์ฌ์ฉํ๋ ํธ๋ฆฌ๊ฐ ๋ง์์ ธ ๋ค์์ฑ์ด ๊ฐ์)
- class_weight (imbalanced ํด๋์ค์ธ ๊ฒฝ์ฐ ์๋)
XGBoost
- learning_rate (๋์๊ฒฝ์ฐ ๊ณผ์ ํฉ ์ํ์ด ์์ต๋๋ค)
- max_depth (๋ฎ์๊ฐ์์ ์ฆ๊ฐ์ํค๋ฉฐ ํ๋, ๋๋ฌด ๊น์ด์ง๋ฉด ๊ณผ์ ํฉ์ํ, -1 ์ค์ ์ ์ ํ ์์ด ๋ถ๊ธฐ, ํน์ฑ์ด ๋ง์ ์๋ก ๊น๊ฒ ์ค์ )
- n_estimators (๋๋ฌด ํฌ๊ฒ ์ฃผ๋ฉด ๊ธด ํ์ต์๊ฐ, early_stopping_rounds์ ๊ฐ์ด ์ฌ์ฉ)
- scale_pos_weight (imbalanced ๋ฌธ์ ์ธ ๊ฒฝ์ฐ ์ ์ฉ์๋)
'๐ฟ Data > ๋ถํธ์บ ํ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TIL]37_Section2_sprint3_challenge (0) | 2022.01.06 |
---|---|
[TIL]36_Interpreting ML Model (0) | 2022.01.05 |
[TIL]34.Data Wrangling (0) | 2022.01.03 |
[TIL]33.Choose your ML problems (0) | 2022.01.01 |
[TIL]32.Section2 Sprint2 Chall(Sprint2 ํค์๋ ์ค์ฌ ์ ๋ฆฌ) (0) | 2021.12.31 |