asadoughi / stat-learning

Notes and exercise attempts for "An Introduction to Statistical Learning"
http://asadoughi.github.io/stat-learning
2.12k stars 1.62k forks source link

Ch3 Ex9c #99

Open actuarialcat opened 5 years ago

actuarialcat commented 5 years ago

The question requires the use of multiple linear regression. The predictor "origin" is stored as a num, but it is a qualitative data. Shouldn't it be change to factor using the following code before doing the regression?


origin_fac = factor(Auto$origin, levels = c("American","European","Japanese"))
new_data = subset(Auto, select = -c(name,origin))
new_data = new_data.frame(new_data, origin_fac)
lm.fix =  lm(mpg~. ,data= new_data)