## problem 1 (Logistic Regression and KNN)
library(ISLR)
attach(Auto)
## creating binary variable for MPG
MPG = rep("Below", length(mpg))
MPG[mpg > mean(mpg)] = "Above"
Auto = data.frame(Auto, MPG)
## a.
# 80% training set
set.seed(1)
train=sample(nrow(Auto),nrow(Auto)*0.8)
## logistic regression
glm.fit=glm(as.factor(MPG)~weight+displacement+horsepower+acceleration,family="binomial",subset=train)
summary(glm.fit)
## except for acceleration, weight, displacement and horsepower are appeared to be statically
## significant since their P values are smaller than the level of significance.
## odds ratio
exp(coef(glm.fit))
## weight: 1.001645e+00
## displacement: 1.013375e+00
## horsepower: 1.052735e+00
## acceleration: 1.079167e+00
############################