## X1 X2 Y
## 1 3 4 Red
## 2 1 2 Red
## 3 3 3 Red
## 4 1 4 Red
## 5 2 1 Blue
## 6 4 3 Blue
## 7 4 1 Blue
Load the e1071 package
Read in the dementia data “dementia2.csv” into a data frame called dat.
Generate a table of the elements in the MacCohort_kr variable (1 point)
Set the random seed to 7 and then split the data into 2 sets (440 train, and 220 test)
Fit a support vector machine to the multiclass outcome of MacCohort_kr and predictors Left_MTG_middle_temporal_gyrus, Left_Amygdala and Left_AIns_anterior_insula, with a radial basis kernel and no rescaling on the training data. Set cost = 1 and gamma = 0.0001. (3 points)
What kind of approach is svm taking to generate a multiple class prediction? Briefly describe the approach and any limitations thereof. (3 points)
Determine the predictions of the SVM fit on the test dataset. (1 points)
Calculate the predictive accuracy of the SVM fit in the test set (1 points)
Is this doing worse than guessing at random? Why/why not? (2 points)
Now use cross-validation in the training data to find the best combination of cost and gamma among the possible values of cost = 0.01, 0.1, 1, 10, 100, and of gamma = 0.00001, 0.0001, 0.01, 0.1, 1. First set the seed to 5. (4 points)
Now fit the SVM to the full training data with the optimal parameters and determine the classification accuracy in the test set. (2 points)
How does the accuracy with the optimized parameters compare with that of the original choice? (1 point)