심화프로젝트: XGBoost를 활용한 LendingClub 대출 상환 예측 모델 개선
✅ 1. XGBoost 기본 모델 적용
XGBClassifier 기본 파라미터로 훈련
- 성능지표:
- Accuracy: 0.65
- Confusion Matrix:
[[33332 15831], [73377 129092]]
- ROC-AUC:
0.7168
- 클래스 0 (상환 실패)에 대한 재현율이 상대적으로 우수
✅ 2. 데이터 불균형 해결: SMOTE 적용
imblearn.over_sampling.SMOTE 사용하여 minority class를 oversampling
- 클래스 비율 균등화 → 모델 학습 전 더 균형잡힌 데이터 구성
✅ 3. 하이퍼파라미터 튜닝 (RandomizedSearchCV)
{
'n_estimators': 200,
'max_depth': 8,
'learning_rate': 0.05,
'colsample_bytree': 0.6,
'subsample': 1.0
}
- 성능 개선:
- Accuracy: 0.81
- Confusion Matrix:
[[3609 45554], [2791 199678]]
- ROC-AUC:
0.7189
- 정확도 및 AUC 향상, 그러나 클래스 0 예측 약화됨 (재현율 ↓)
✅ 4. 변수 제거 실험
grade, installment 제거 후 모델 재학습
- 큰 성능 차이는 없었으나, 모델의 해석 가능성 제고를 위해 시도
✅ 5. 모델 평가 시각화 및 중요 변수 해석
xgb.feature_importances_를 통해 주요 변수 시각화
- 상위 변수:
grade, term, home_ownership, verification_status, purpose 등
6. 코드
from xgboost import XGBClassifier
from sklearn.metrics import classification_report, confusion_matrix, roc_auc_score
from sklearn.model_selection import train_test_split
X3_reduced = X3.drop(columns=['grade','installment'])
X_train, X_test, y_train, y_test = train_test_split(X3_reduced, y, test_size=0.2, random_state=42, stratify=y)
xgb = XGBClassifier(
n_estimators=100,
max_depth=5,
learning_rate=0.1,
scale_pos_weight=(y_train.value_counts()[0] / y_train.value_counts()[1]),
random_state=42,
eval_metric='logloss',
use_label_encoder=False
)
xgb.fit(X_train, y_train)
y_pred = xgb.predict(X_test)
y_pred_proba = xgb.predict_proba(X_test)[:, 1]
print("📦 Confusion Matrix")
print(confusion_matrix(y_test, y_pred))
print("\n📊 Classification Report")
print(classification_report(y_test, y_pred))
print(f"\n🎯 ROC-AUC: {roc_auc_score(y_test, y_pred_proba):.4f}")
오늘의 인사이트
- SMOTE로 데이터 불균형은 해결했지만, XGBoost는 여전히 클래스 0 예측력이 낮음
- 하이퍼파라미터 튜닝은 성능 향상에 효과적이지만, Recall 관점에서는 주의 필요
- 중요한 변수를 제거해도 성능 변화는 미미 → 불필요한 변수 제거 가능성 검토 필요
- 향후 개선 방향:
threshold 조정, 앙상블 모델, SMOTE-ENN, 모델 스태킹 등 적용 예정