C.W.K.
Stream
Lesson 04 of 08 · published

Train / Validation / Test Split

~30 min · splits, validation, evaluation

Level 0Scout
0 XP0/48 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

세 역할, 세 set

Training data가 모델을 fit. Validation data가 hyperparameter를 튜닝하고 모델 사이 선택. Test data는 한 질문에만 답해 — validation에서 한 결정이 일반화됐나? 최종 모델 freeze 전에 test score를 한 번이라도 보면, test set이 또 다른 validation set이 되고 정직한 추정치를 잃는 거야.

Stratify, group, time-respect

class imbalance 있는 classification은 label로 stratify. group 데이터(user 당 여러 row)는 user로 split. time-series는 time으로 split하고 미래 row가 절대 training에 못 들어오게 해. 전략 섞으면 leaderboard가 game 당하고 production system이 부끄러워져.

frozen test set 의식

day 1에 test set의 index를 pickle하고 다시 계산하지 마. 데이터가 바뀌면 새 dataset을 만들어. test set을 슬쩍 옮기는 거 아냐. frozen-test-set 의식이 calibrate된 팀과 자기 자신에게 거짓말하는 팀의 차이야.

Code

binary classification을 위한 stratified split·python
from sklearn.model_selection import train_test_split

X_train, X_temp, y_train, y_temp = train_test_split(
    X, y, test_size=0.30, stratify=y, random_state=7
)
X_val, X_test, y_val, y_test = train_test_split(
    X_temp, y_temp, test_size=0.50, stratify=y_temp, random_state=7
)
한 user에 여러 row일 때 group-aware split·python
from sklearn.model_selection import GroupShuffleSplit

splitter = GroupShuffleSplit(n_splits=1, test_size=0.2, random_state=7)
train_idx, test_idx = next(splitter.split(X, y, groups=df["user_id"]))
forecasting을 위한 time-respecting split·python
cutoff = "2026-04-01"
train = df[df["event_time"] < cutoff]
test  = df[df["event_time"] >= cutoff]

External links

Exercise

dataset에 맞는 split 전략(random stratified / grouped / time-respecting)을 결정. train/val/test index 만드는 코드를 써. test index를 디스크에 저장하고 immutable로 다뤄.

Progress

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

댓글 0

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

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