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

Bias-Variance Tradeoff

~26 min · bias, variance, theory

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

분해

Generalization error가 bias squared(평균 prediction이 truth에서 얼마나 멈), variance(training set 사이 prediction이 얼마나 wobble), irreducible noise로 분해. 용량 적은 모델이 high bias. 용량 너무 많은 모델이 high variance. sweet spot은 합 최소화.

도구가 trade-off를 어떻게 바꾸나

  • Regularization이 variance 낮추려고 bias 올림.
  • 데이터 더는 bias 안 바꾸고 variance 낮춤.
  • Bagging(random forest)이 high-variance tree를 평균 내서 variance 낮춤.
  • Boosting이 error를 sequentially 보정해서 bias 낮춤. 안 잡으면 overfit.

왜 중요한가

둘 다 한 번에 제거 못 해. 어느 게 현재 모델을 지배하는지 알면 다음에 어떤 손잡이 돌릴지 알아. high train accuracy + low validation accuracy = variance 문제. 둘 다 low = bias 문제. 프레임워크가 추측 몇 주 절약.

Code

bootstrap으로 bias와 variance 경험적 분리·python
import numpy as np
from sklearn.utils import resample

predictions = []
for _ in range(50):
    Xb, yb = resample(X_train, y_train, random_state=None)
    fit = pipe.fit(Xb, yb)
    predictions.append(fit.predict_proba(X_test)[:, 1])

preds = np.array(predictions)
mean_pred = preds.mean(axis=0)
var_pred = preds.var(axis=0)
print("mean variance across bootstrap models:", var_pred.mean())
high-variance 모델 줄이는 bagging·python
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier

bag = BaggingClassifier(
    estimator=DecisionTreeClassifier(max_depth=None),
    n_estimators=200, random_state=7, n_jobs=-1
).fit(X_train, y_train)

External links

Exercise

best 모델에 대해, 5개 random seed에 걸쳐 training score vs validation score plot. seed 사이 variance 낮은데 gap 크면 bias. gap 작은데 seed 사이 validation score wobble하면 variance. 다음 fix에 손잡이 하나 골라.

Progress

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

댓글 0

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

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