November 2016
Beginner to intermediate
959 pages
43h 46m
English
The MASS package has the functionality for variable selection and this recipe illustrates its use.
If you have not already done so, download the data files for this chapter and ensure that the auto-mpg.csv file is in your R working directory. We want to predict mpg based on cylinders, displacement, horsepower, weight, and acceleration.
To perform variable selection in linear regression, follow the steps below:
caret and MASS packages:> library(caret) > library(MASS)
> auto <- read.csv("auto-mpg.csv")> auto$cylinders <- factor(auto$cylinders, levels = c(3,4,5,6,8), ...
Read now
Unlock full access