비선형 변환 학습을 위한 GAM

R로 하는 Supervised Learning: 회귀

Nina Zumel and John Mount

Win-Vector, LLC

일반화 가법 모델 (GAM)

$$ y \sim b0 + s1(x1) + s2(x2) + .... $$

R로 하는 Supervised Learning: 회귀

비선형 관계 학습

R로 하는 Supervised Learning: 회귀

mgcv 패키지의 gam() 함수

gam(formula, family, data)

family:

  • gaussian (기본값): "일반" 회귀
  • binomial: 확률
  • poisson/quasipoisson: 빈도

대규모 데이터셋에 적합

R로 하는 Supervised Learning: 회귀

s() 함수

anx ~ s(hassles)
  • s()는 해당 변수를 비선형으로 지정
  • 연속형 변수에 s() 사용
    • 고유값이 약 10개 이상인 경우
R로 하는 Supervised Learning: 회귀

hassles 데이터 재검토

R로 하는 Supervised Learning: 회귀

hassles 데이터 재검토

모델 RMSE (교차 검증) $R^2$ (훈련)
선형 ($hassles$) 7.69 0.53
2차 ($hassles^2$) 6.89 0.63
3차 ($hassles^3$) 6.70 0.65
R로 하는 Supervised Learning: 회귀

hassles 데이터의 GAM

model <- gam(
  anx ~ s(hassles), 
  data = hassleframe, 
  family = gaussian
)

summary(model)
...

R-sq.(adj) =  0.619   Deviance explained = 64.1%
GCV = 49.132  Scale est. = 45.153    n = 40
R로 하는 Supervised Learning: 회귀

변환 결과 살펴보기

plot(model)

$y$ 값: predict(model, type = "terms")

R로 하는 Supervised Learning: 회귀

모델로 예측하기

predict(model, newdata = hassleframe, type = "response")

R로 하는 Supervised Learning: 회귀

표본 외 성능 비교

올바른 변환을 아는 것이 가장 좋지만, 변환을 모를 때는 GAM이 유용합니다

모델 RMSE (교차 검증) $R^2$ (훈련)
선형 ($hassles$) 7.69 0.53
2차 ($hassles^2$) 6.89 0.63
3차 ($hassles^3$) 6.70 0.65
GAM 7.06 0.64
  • 소규모 데이터셋 $\rightarrow$ GAM의 노이즈 증가
R로 하는 Supervised Learning: 회귀

연습해 봅시다!

R로 하는 Supervised Learning: 회귀

Preparing Video For Download...