[Dacon] 채무 불이행 여부 예측 해커톤: 불이행의 징후를 찾아라!

Gongsam·2025년 3월 14일
0

dacon

목록 보기
1/2

사용해본 모델

XGBoostClassifier

  • 베이스라인 코드로 제공됨

LightGBM

  • XGB 대안용으로 사용해봄
  • Radomized_search 이용
# 하이퍼파라미터 분포 설정 (랜덤 서치를 위해)
param_dist = {
    'learning_rate': np.linspace(0.01, 0.2, 20),  # 0.01부터 0.2까지 균등 분포
    'n_estimators': [50, 100, 200, 500],          # 트리 개수
    'max_depth': [3, 5, 7, 10, 15],               # 트리의 최대 깊이
    'num_leaves': [31, 50, 70, 100],              # 리프의 개수
    'subsample': np.linspace(0.6, 1.0, 5),        # 샘플링 비율
    'colsample_bytree': np.linspace(0.6, 1.0, 5)  # 특성 샘플링 비율
}

# 모델 정의
light_model = lgb.LGBMClassifier()

# RandomizedSearchCV 정의
random_search = RandomizedSearchCV(
    estimator=light_model,
    param_distributions=param_dist,
    n_iter=100,      # 100번 랜덤 샘플링을 시도
    cv=5,            # 5-폴드 교차 검증
    n_jobs=-1,       # 모든 코어 사용
    verbose=1,       # 진행 상황 출력
    random_state=42  # 랜덤 시드 고정
)

결과

0.5932875554

Catboost

처음으로 0.6 넘김!

  • 자체 randomized_search 메소드가 있음
cat_model = CatBoostClassifier(verbose=0)

# 하이퍼파라미터 그리드 설정
param_grid = {
    'iterations': [500, 1000, 1500],
    'learning_rate': [0.01, 0.05, 0.1],
    'depth': [4, 6, 8],
    'l2_leaf_reg': [1, 3, 5],
}


randomized_cat = cat_model.randomized_search(
    param_distributions=param_grid,
    X=X_train,
    y=y_train,
    cv=5,
    n_iter=100,  # 100개의 랜덤 조합만 탐색
    partition_random_seed=42,
    stratified=True,
    refit=True
)

# 최적의 하이퍼파라미터 가져오기
best_params = randomized_cat['params']
print("Best parameters found:", best_params)

# ⚡ 최적 하이퍼파라미터로 새 모델 훈련 (이때 얼리 스토핑 적용!)
best_model = CatBoostClassifier(**best_params, verbose=100)
best_model.fit(
    X_train, y_train,
    eval_set=(X_val, y_val),  # 검증 데이터 추가
    early_stopping_rounds=50,     # 얼리 스토핑 적용
    use_best_model=True
)
  • border_count, bagging_temperature은 randomized_search에 포함하지 않는 것이 더 성능이 좋았음

결과

0.6014728566

Catboost 2

원핫 인코딩 사용하지 않고 자체 parameter 사용
=> 이게 더 결과값이 떨어짐

from catboost import CatBoostClassifier

categorical_col = [
    '주거 형태',
    '현재 직장 근속 연수',
    '대출 목적',
    '대출 상환 기간'
]

cat_model = CatBoostClassifier(
    verbose=0,
    cat_features=categorical_col)

# 하이퍼파라미터 그리드 설정
param_grid = {
    'iterations': [500, 1000, 1500],
    'learning_rate': [0.01, 0.05, 0.1],
    'depth': [4, 6, 8],
    'l2_leaf_reg': [1, 3, 5],
}


randomized_cat = cat_model.randomized_search(
    param_distributions=param_grid,
    X=X_train,
    y=y_train,
    cv=5,
    n_iter=100,  # 100개의 랜덤 조합만 탐색
    partition_random_seed=42,
    stratified=True,
    refit=True,
    verbose=1
)
# 최적의 하이퍼파라미터 가져오기
best_params = randomized_cat['params']
print("Best parameters found:", best_params)

# 최적 하이퍼파라미터로 새 모델 훈련
best_model = CatBoostClassifier(**best_params, cat_features=categorical_col, verbose=100)
best_model.fit(
    X_train, y_train,
    eval_set=(X_val, y_val),  # 검증 데이터 추가
    early_stopping_rounds=50,     # 얼리 스토핑 적용
    use_best_model=True
)

결과

0.5984574812

시도한 방법

상관관계 분석, 다중공선성 확인

  • 딱히 높은 상관관계를 갖는 경우는 없었음

matplotlib 한글화

# 구글 코랩에 한글 폰트를 설치
!apt-get update -qq
!apt-get install -qq fonts-nanum

# 설치된 폰트를 확인
!fc-list :lang=ko
plt.rcParams['font.family'] ='NanumGothic'
plt.rcParams['axes.unicode_minus'] =False
  • 나눔고딕으로 설정하는 방법
profile
🐬 파이썬 / 인공지능 / 머신러닝

0개의 댓글