Вы находитесь на странице: 1из 21

GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.

com/blog/2015/07/30/gam/

1 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

2 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

3 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

4 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

set.seed(3)
x <- seq(0,2*pi,0.1)
z <- sin(x)
y <- z + rnorm(mean=0, sd=0.5*sd(z), n=length(x))
d <- cbind.data.frame(x,y,z)

5 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

6 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

7 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

8 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

9 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

### GAM example using mgcv

library(mgcv)
library(ggplot2)
# fake data
n <- 50
sig <- 2
dat <- gamSim(1,n=n,scale=sig)

# P-spline smoothers (with lambda=0.6) used for x1 and x2; x3 is parametric.

10 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

ggplot(data=cbind.data.frame(s, dat$x1), aes(x=dat$x1, y=s)) + geom_line()

# predict
newdf <- gamSim(1,n=n,scale=sig)
f <- predict(b1, newdata=newdf)

# select smoothing parameters with REML, using P-splines


b2 <- mgcv::gam(y ~ s(x1, bs='ps') + s(x2, bs='ps') + x3, data = dat, method="REML"

# select variables and smoothing parameters


b3 <- mgcv::gam(y ~ s(x0) + s(x1) + s(x2) + s(x3) , data = dat, method="REML", select

# loess smoothers with the gam package (restart R before loading gam)
library(gam)
b4 <- gam::gam(y ~ lo(x1, span=0.6) + lo(x2, span=0.6) + x3, data = dat)
summary(b4)

11 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

12 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

13 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

14 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

15 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

16 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

17 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

18 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

19 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

20 of 21 13/09/2018, 18:50
GAM: The Predictive Modeling Silver Bullet | Stitch Fix Technology ... https://multithreaded.stitchfix.com/blog/2015/07/30/gam/

21 of 21 13/09/2018, 18:50

Вам также может понравиться