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

Missing Value와 Outlier

~30 min · missing, outliers, preprocessing

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

missing이 의미를 갖는다

missingness가 정보를 담아. 어떤 row가 missing 인지 패턴이 종종 target과 상관관계가 있어. imputed value 옆에 binary `was_missing` indicator를 추가하면 그 signal이 보존돼.

imputation 전략, lift 순

  1. 도메인 특화 fill ("never bought"는 0, "unknown"은 -1).
  2. missingness indicator 곁들인 median 또는 mode imputation.
  3. 강한 feature 상관관계가 있는 tabular엔 iterative 또는 KNN imputation.
  4. tree model(lightgbm, xgboost)의 native missing handling — missing 위에서 split 하게 둬.

증거로서의 outlier

outlier가 때론 data-entry 버그, 때론 dataset에서 제일 중요한 row. column마다 clip / log-transform / 그대로 모델 / 별도 모델로 split할지 결정해. outlier를 무턱대고 지우면 가장 중요한 고객들을 버리는 거야.

Code

missingness indicator를 동반한 SimpleImputer·python
from sklearn.impute import SimpleImputer
from sklearn.compose import ColumnTransformer

numeric_imputer = SimpleImputer(strategy="median", add_indicator=True)
ct = ColumnTransformer([
    ("num", numeric_imputer, numeric_cols),
])
robust outlier handling: 지우지 말고 clip·python
import numpy as np

def robust_clip(s):
    q1, q3 = s.quantile([0.01, 0.99])
    return s.clip(q1, q3)

df["amount_clipped"] = robust_clip(df["amount"])
lightgbm이 missing을 native로 다루게·python
import lightgbm as lgb

model = lgb.LGBMClassifier(
    n_estimators=400, learning_rate=0.05, max_depth=-1
).fit(X_train, y_train)

External links

Exercise

dataset에서 missing 비율 가장 높은 column 3개를 골라. 각각에 도메인 fill / median + indicator / native tree handling 중 결정. column 당 한 문장으로 정당화해.

Progress

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

댓글 0

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

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