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

Underfitting, Overfitting, 그리고 Regularization

~30 min · regularization, ridge, lasso

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

두 실패 모드

Underfitting: 모델이 training data 위에서도 구조를 못 잡아. training loss 높고 validation loss 비슷. 용량 / feature / 표현 추가로 fix. Overfitting: 모델이 training data를 외워. training loss 작고 validation loss 훨씬 나빠. 용량 줄이거나 regularize 하거나 데이터 더 얻어서 fix.

Ridge, Lasso, Elastic Net

Ridge(L2)가 계수를 0 쪽으로 shrink하지만 정확히 0으로는 강제 안 해. Lasso(L1)가 shrink하고 작은 계수를 0으로 만들어 feature selection 수행. Elastic Net이 weighted 조합, high-dimensional tabular에 종종 가장 안전한 default. 튜닝 손잡이는 α(alpha): 클수록 더 shrink.

튜닝 방법

cross-validation으로 alpha를 자동 선택하는 RidgeCV / LassoCV / ElasticNetCV를 써. validation curve를 plot 해서 바닥에 있는지 절벽 근처인지 봐. regularization은 항상 feature scale 먼저 하는 pipeline 안에서 돌려.

Code

RidgeCV가 alpha 자동 선택·python
from sklearn.linear_model import RidgeCV
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import numpy as np

alphas = np.logspace(-3, 3, 25)
pipe = Pipeline([("scale", StandardScaler()), ("ridge", RidgeCV(alphas=alphas))])
pipe.fit(X_train, y_train)
print("chosen alpha:", pipe.named_steps["ridge"].alpha_)
bias-variance trade 보는 validation curve·python
from sklearn.model_selection import validation_curve

train_scores, val_scores = validation_curve(
    Ridge(), X_train_scaled, y_train,
    param_name="alpha", param_range=alphas,
    cv=5, scoring="neg_root_mean_squared_error",
)

External links

Exercise

같은 문제에 cross-validated alpha 동반한 Ridge, Lasso, ElasticNet train. test set 위 RMSE와 0 아닌 계수 개수 비교. 어느 걸 ship 할지와 이유.

Progress

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

댓글 0

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

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