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

Linear이 통할 때와 깨질 때

~26 min · linear, limitations

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

linear가 빛나는 곳

Linear model이 적절한 transformation 후 feature와 target 사이 관계가 대략 additive일 때, dataset이 small to medium일 때, interpretability가 필요할 때, GPU 안 필요한 안정 artifact를 ship 해야 할 때 탁월.

linear가 깨지는 곳

  • Strong interaction — A의 효과가 B에 의존. interaction term 추가하거나 tree로.
  • Non-monotone 관계 — y가 X와 함께 올라갔다 내려가. feature를 binning, spline 사용, 또는 tree로.
  • Heteroscedastic noise — residual 분산이 prediction에 의존. log-target, weighted regression, 또는 quantile regression 시도.
  • High-cardinality categorical — one-hot이 폭발. target encoding이나 tree.

정직한 upgrade path

linear가 깨졌을 때 deep neural net으로 바로 점프하지 마. 중간 지대는 gradient boosted tree야. interaction, non-monotonicity, missingness, high cardinality 다 처리하면서도 train 빠르고 interpret 가능.

Code

linear model엔 명시적 interaction feature 추가·python
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import Pipeline
from sklearn.linear_model import Ridge

pipe = Pipeline([
    ("poly", PolynomialFeatures(degree=2, interaction_only=True, include_bias=False)),
    ("ridge", Ridge(alpha=1.0)),
])
헷갈릴 땐 gradient boosting 시도·python
import lightgbm as lgb

model = lgb.LGBMRegressor(n_estimators=500, learning_rate=0.05).fit(
    X_train, y_train, eval_set=[(X_val, y_val)], callbacks=[lgb.early_stopping(20)]
)

External links

Exercise

dataset에 Ridge 모델과 LightGBM regressor fit. RMSE와 residual plot 비교. LightGBM이 RMSE 5% 미만으로 이기면 Ridge ship. 세 문장으로 정당화.

Progress

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

댓글 2

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

    회귀분석 강의에서 반드시 짚고 넘어가야 할 함정 있잖아. 만약 데이터가 범죄발생수(target), 연도, 인구수, 교회수 라고 하자. 회귀 분석을 한다면 해당 데이터는 범죄발생수와 교회수의 증가가 밀접한 관계를 이루게 되고 결국 "교회수가 많을수록 범죄가 많다" 는 통계적으로 유의한 양(+)의 계수가 나올수가 있잖아, 이러한 모순을 필터링하는 단계가 있을까?

    💛 by 똘이warm💛 by 피파warm
    1. 피파
      피파· seriousyoung-hoon Kimyoung-hoon Kim

      네, 이건 회귀분석에서 아주 중요한 함정이에요. 자동으로 “모순 필터”가 따로 있는 건 아니고, 모델링 전에 범죄발생수를 인구 대비 비율로 바꾸고, 연도·인구·도시화 같은 공통 원인을 함께 통제한 뒤, 그래도 교회수 계수가 남는지 봐야 해요.

      핵심은 “통계적으로 유의하다”가 곧 “원인이다”는 뜻이 아니라는 점이에요. 이 예시는 오히려 상관관계와 인과관계를 구분하는 좋은 사례라서, regression quest 안에서도 꼭 한 번 다룰 만한 함정이에요.