1. ๊ฐ์
์์ธ์ ํ์ง์ ์์ธกํ๋ ๊ฒ์ ๋จธ์ ๋ฌ๋์์ ํํ ๋ค๋ฃจ๋ ๋ฌธ์ ์ค ํ๋์ด๋ค. Wine Quality Dataset์ ์์ธ์ ํํ์ ํน์ฑ์ ๊ธฐ๋ฐ์ผ๋ก ํ์ง์ ์์ธกํ๋ ๋ฐ์ดํฐ์ ์ผ๋ก, ํ๊ท ๋ฌธ์ ์ ํด๋นํ๋ค. ์ด๋ฒ ๊ธ์์๋ CatBoost๋ฅผ ์ฌ์ฉํ์ฌ ์์ธ ํ์ง์ ์์ธกํ๋ ๋ชจ๋ธ์ ๋ง๋ค์ด ๋ณผ ๊ฒ์ด๋ค.
2. Wine Quality Dataset ์๊ฐ
Wine Quality Dataset์ UCI Machine Learning Repository์์ ์ ๊ณตํ๋ ๊ณต๊ฐ ๋ฐ์ดํฐ์ ์ผ๋ก, ๋ ๋ ์์ธ๊ณผ ํ์ดํธ ์์ธ์ ๋ํ ํ์ง ์ ๋ณด๋ฅผ ํฌํจํ๊ณ ์์.
- ํน์ฑ(features): 11๊ฐ์ ํํ์ ์ฑ๋ถ (์: pH, ์์ฝ์ฌ, ํฉ์ฐ์ผ ๋ฑ)
- ๋ ์ด๋ธ(label): 0~10๊น์ง์ ํ์ง ์ ์ (ํ๊ท ๋ฌธ์ )
์ด ๋ฐ์ดํฐ์ ์ ์ฌ๊ธฐ์์ ๋ค์ด๋ก๋ ๊ฐ๋ฅํจ.
3. CatBoost ์ค์น
CatBoost๋ ๋ค์ ๋ช ๋ น์ด๋ก ๊ฐ๋จํ ์ค์นํ ์ ์์.
# conda config --add channels conda-forge
# conda install catboost
pip install catboost
4. ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ ๋ฐ ์ ์ฒ๋ฆฌ
Python์ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ์ ์ ๋ถ๋ฌ์ค๊ณ , ์ ์ฒ๋ฆฌ๋ฅผ ์งํํจ.
import pandas as pd
from sklearn.model_selection import train_test_split
from catboost import CatBoostRegressor
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
# ๋ฐ์ดํฐ ๋ก๋
# ๋๋ ๋๋ ํ ๋ฆฌ ์์น์ ๋ง๊ฒ ๋ถ๋ฌ์ค๊ธฐ
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv", sep=';')
# ์
๋ ฅ(X)์ ํ๊ฒ(y) ๋ถ๋ฆฌ
X = df.drop(columns=['quality'])
y = df['quality']
# ํ์ต ๋ฐ์ดํฐ์ ํ
์คํธ ๋ฐ์ดํฐ ๋ถ๋ฆฌ
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
print(f"Train ๋ฐ์ดํฐ ํฌ๊ธฐ: {X_train.shape}")
print(f"Test ๋ฐ์ดํฐ ํฌ๊ธฐ: {X_test.shape}")
# Train ๋ฐ์ดํฐ ํฌ๊ธฐ: (1279, 11)
# Test ๋ฐ์ดํฐ ํฌ๊ธฐ: (320, 11)
5. CatBoost ๋ชจ๋ธ ํ์ต
CatBoost๋ฅผ ์ฌ์ฉํ์ฌ ์์ธ์ ํ์ง์ ์์ธกํ๋ ํ๊ท ๋ชจ๋ธ์ ํ์ตํจ.
# CatBoost ๋ชจ๋ธ ์์ฑ ๋ฐ ํ์ต
model = CatBoostRegressor(iterations=1000, depth=6, learning_rate=0.1, loss_function='MAE', verbose=200)
model.fit(X_train, y_train)
# ์์ธก
y_pred = model.predict(X_test)
ํ๋ผ๋ฏธํฐ ์ค๋ช
- iterations=1000: 1000๋ฒ ๋ฐ๋ณต ํ์ต
- depth=6: ํธ๋ฆฌ ๊น์ด ์ค์ (๊ฐ์ด ํด์๋ก ๋ณต์กํ ๋ชจ๋ธ)
- learning_rate=0.1: ํ์ต๋ฅ ์ค์
- loss_function='MAE': Mean Absolute Error(MAE)๋ฅผ ์์ค ํจ์๋ก ์ฌ์ฉ
6. ๊ฒฐ๊ณผ ๋ถ์
# ๋ชจ๋ธ ํ๊ฐ ํจ์
def evaluate_model(y_true, y_pred, model_name="Model"):
mae = mean_absolute_error(y_true, y_pred)
mse = mean_squared_error(y_true, y_pred)
r2 = r2_score(y_true, y_pred)
print(f"{model_name} Performance:")
print(f"Mean Absolute Error (MAE): {mae:.4f}")
print(f"Mean Squared Error (MSE): {mse:.4f}")
print(f"R² Score: {r2:.4f}\n")
evaluate_model(y_test, y_pred, "CatBoost")
# CatBoost Performance:
# Mean Absolute Error (MAE): 0.4268
# Mean Squared Error (MSE): 0.3330
# R² Score: 0.4904
์ ๊ฒฐ๊ณผ์์ MAE๊ฐ 0.43 ์์ค์ผ๋ก ๋์์. ์ฆ, ํ๊ท ์ ์ผ๋ก ์ฝ 0.43์ ์ ์ค์ฐจ๋ก ํ์ง์ ์์ธกํ๋ค๋ ์๋ฏธ์.
7. CatBoost vs. XGBoost
์ด์ ์ ์งํํ๋ ๊ฒฐ๊ณผ์ ๋น๊ตํ๋ฉด ๋ค์๊ณผ ๊ฐ์.
Model | MAE | MSE | R² Score |
CatBoostRegressor | 0.4268 | 0.3330 | 0.4904 |
XGBoost (Baseline) | 0.4175 | 0.3513 | 0.4625 |
XGBoost (Scaled) | 0.4175 | 0.3513 | 0.4625 |
XGBoost (Outliers Removed) | 0.4383 | 0.3492 | 0.4656 |
XGBoost (Tuned) | 0.4549 | 0.3506 | 0.4635 |
Catboost ๋ชจ๋ธ์ด MAE ๊ฐ์ ๊ฐ์ฅ ๋ฎ์ง ์์์ง๋ง, MSE ๊ฐ์ด ๊ฐ์ฅ ๋๊ณ R² Score ๊ฐ์ด ๊ฐ์ฅ ๋์๊ฒ์ ํ์ธํจ.
8. ๊ฒฐ๋ก
CatBoost๋ ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ๋ฅผ ์ต์ํํ๋ฉด์๋ ๋์ ์ฑ๋ฅ์ ์ ๊ณตํ๋ ๊ฐ๋ ฅํ ๋จธ์ ๋ฌ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์. ์ด๋ฒ ์คํ์์๋ Wine Quality Dataset์ ์์ธกํ๋ ํ๊ท ๋ชจ๋ธ์ ํ์ตํ์๊ณ , ๋ฒ ์ด์ค๋ผ์ธ ๋ชจ๋ธ๋ก๋ ๋์ ์ฑ๋ฅ์ ๋ด๋๊ฒ์ ํ์ธํจ.
CatBoost์ ์ฅ์ ์ ๋ฆฌ
- ๋ณ๋ ๋ฒ์ฃผํ ๋ฐ์ดํฐ ๋ณํ ์์ด ์ฌ์ฉ ๊ฐ๋ฅ
- ๋น ๋ฅธ ํ์ต ๋ฐ ์์ธก ์๋
- ๊ธฐ๋ณธ ํ์ดํผํ๋ผ๋ฏธํฐ๋ก๋ ์ฐ์ํ ์ฑ๋ฅ