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$危覿)