Copy of Assignment 9.txt

# Copy of Assignment 9.txt - #Problem 1#In this problem you...

• Homework Help
• 3

This preview shows pages 1–2. Sign up to view the full content.

#Problem 1 #In this problem, you will use support vector approaches to predict whether a given car gets high #or low gas mileage based on the Auto data set in the ISLR package. #(a) Create a binary variable that takes on a 1 for cars with gas mileage above the median, and a 0 #for cars with gas mileage below the median. Use this variable as response in the following analysis. install.packages("dplyr") library(ISLR) library(e1071) library(dplyr) attach(Auto) Auto1 <- Auto var <- ifelse(Auto\$mpg > median(Auto\$mpg), 1, 0) Auto\$mpglevel <- as.factor(var) plot(Auto) auto_data <- select(Auto, c(displacement, horsepower, weight, acceleration, mpglevel)) #(b) Fit a support vector classifier to the data with various values of cost, to predict whether a car #gets high or low gas mileage. Report the cross-validation errors associated with different values of #this parameter. Comment on your results. set.seed(1) ### divide into equal sets of testing and training data train <- sample(1:dim(auto_data)[1], dim(auto_data)[1] / 2) test <- -train train.auto = auto_data[train, ] test.auto = auto_data[test, ] # Run the SVM tune.out.linear <- tune(svm, mpglevel ~ ., data = train.auto, kernel = "linear", ranges = list(cost = c(0.001, 0.01, 0.1, 1, 5, 10, 100))) best.auto.linear <- tune.out.linear\$best.model summary(best.auto.linear) y.prediction.linear <- predict(best.auto.linear, test.auto) linear <- table(predict = y.prediction.linear, truth =

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Fall '16
• Support vector machine, SVMs, support vector

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern