C.W.K.
Stream
Lesson 05 of 06 · published

Class imbalance 처리

~8 min · data

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

imbalanced 데이터 — 한 class 가 90%, 다른 게 10% — 그냥 학습하면 모델이 '항상 majority' 로 90% 정확도. 대응 layer 별: (1) data — oversample minority 또는 undersample majority. (2) loss — class_weight={0: 0.5, 1: 5.0} 으로 minority 의 loss 증폭. focal loss 도 옵션.

(3) threshold — sigmoid 출력의 decision threshold 를 0.5 가 아니라 0.3 으로 낮춰 — recall ↑. 한 가지로 안 풀리는 경우 多 — 둘 이상 조합이 흔해.

Code

# 1. class_weight in model.fit()
model.fit(x, y, class_weight={{0: 1.0, 1: 10.0}})

# 2. sample_weight array (per-sample importance)
weights = np.where(y_train == 1, 10.0, 1.0)
model.fit(x, y, sample_weight=weights)

# 3. Oversample minority class in the pipeline
# (duplicate minority samples or use SMOTE)

External links

Exercise

MNIST 를 인위적으로 imbalanced 만들어 (한 class 90%, 나머지 10%). class_weight 없이/적용 학습. minority class 의 precision / recall 비교 — class_weight 가 trade-off 어떻게 바꾸는지.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.