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

Target Leakage

~32 min · leakage, splits, evaluation

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

leakage가 뭐야

Target leakage는 prediction 시점에 존재하지 않을 정보가 feature에 들어 있는 거야. ML 모델이 노트북에선 멋지고 production에선 실망스러운 가장 흔한 원인이야. leakage는 아름다운 validation 숫자와 deploy 못 할 모델을 동시에 만들어.

세 종류

  • Time leakage — 미래 aggregate 사용 (전체 dataset에 걸쳐 계산된 last-30-days revenue).
  • Post-event leakage — outcome 후에만 존재하는 column (cancel reason, refund amount, 그 이슈 자체에 대한 support call).
  • Preprocessing leakage — split 전에 전체 dataset에 scaler / imputer / encoder를 fit. train statistics가 이제 test set을 안다.

방어

feature를 pipeline 안에서 빌드해, pipeline 전이 아니라. 먼저 split 하고 transformer는 training만 보고 fit. 한 column 빼면 validation score가 비현실적으로 떨어지는 column은 audit해. feature 하나가 모델을 다 캐리하면, 증명 전까지는 leakage야.

Code

잘못: scaler가 test set을 본다·python
# DO NOT DO THIS
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler().fit(X)  # fit on full dataset → leakage
X_scaled = scaler.transform(X)
X_tr, X_te, y_tr, y_te = train_test_split(X_scaled, y)
맞음: scaler가 pipeline 안에 산다·python
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.model_selection import cross_val_score

pipe = Pipeline([
    ("scale", StandardScaler()),
    ("clf", LogisticRegression(max_iter=500)),
])
scores = cross_val_score(pipe, X, y, cv=5, scoring="average_precision")

External links

Exercise

현재 모델에서 importance 상위 5개 feature를 audit해. 각각에 대해 그 feature가 prediction 시점에 존재한다는 한 문장짜리 증명을 써. 증명 못 하는 건 빼고 retrain.

Progress

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

댓글 0

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

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