#title 일반화 가법 모형 {{{ set.seed(602957) x <- rnorm(1000) noise <- rnorm(1000, sd=1.5) y <- 3*sin(2*x) + cos(0.75*x) - 1.5*(x^2 ) + noise select <- runif(1000) frame <- data.frame(y=y, x = x) train <- frame[select > 0.1,] test <-frame[select <= 0.1,] library(mgcv) glin.model <- gam(y~s(x), data=train) summary(glin.model) sx <- predict(glin.model, type="terms") xframe <- cbind(train, sx=sx[,1]) ggplot(xframe, aes(x=x)) + geom_point(aes(y=y), alpha=0.4) + geom_line(aes(y=sx)) }}} 분류 {{{ library("mgcv") model <- gam(이탈여부 ~ s(변수1) + s(변수2),family=binomial, data=training) summary(model) pred <- predict(model, test, type="response") confusionMatrix(ifelse(pred < 0.5, "이탈", "잔존"), test$이탈여부) }}}