8
Questions concerning R language
xuanyi.wang edited this page 2023-05-22 20:41:52 +02:00
Applied Question
This problem involves the OJ data set which is part of the ISLR package.
- i. Create a training set containing a random sample of 800 observations, and a test set containing the remaining observations.
- ii. Fit a support vector classifier to the training data using
cost=0.01, withPurchaseas the response and the other variables as predictors. Use thesummary()function to produce summary statistics, and describe the results obtained. - iii. What are the training and test error rates?
- iv. Use the
tune()function to select an optimal cost. Consider values in the range 0.01 to 10. - v. Compute the training and test error rates using this new value for
cost. - vi. Repeat parts (ii) through (v) using a support vector machine with a radial kernel. Use the default value for
gamma. - vii. Repeat parts (ii) through (v) using a support vector machine with a polynomial kernel. Set
degree=2. - viii. Overall, which approach seems to give the best results on this data?
Conceptual Question
Here we explore the maximal margin classifier on a toy data set.
- i. We are given n = 7 observations in p = 2 dimensions. For each observation, there is an associated class label. Sketch the observations.
| Obs. | X1 | X2 | Y |
|---|---|---|---|
| 1 | 3 | 4 | Red |
| 2 | 2 | 2 | Red |
| 3 | 4 | 4 | Red |
| 4 | 1 | 4 | Red |
| 5 | 2 | 1 | Blue |
| 6 | 4 | 3 | Blue |
| 7 | 4 | 1 | Blue |
- ii. Sketch the optimal separating hyperplane, and provide the equa- tion for this hyperplane.
- iii. Describe the classification rule for the maximal margin classifier. It should be something along the lines of “Classify to Red if β0 + β1X1 + β2X2 > 0, and classify to Blue otherwise.” Provide the values for β0, β1, and β2.
- iv. On your sketch, indicate the margin for the maximal margin hyperplane.
- v. Indicate the support vectors for the maximal margin classifier.
- vi. Argue that a slight movement of the seventh observation would not affect the maximal margin hyperplane.
- vii. Repeat parts (ii) through (v) using a support vector machine with a polynomial kernel. Set
degree=2. Sketch a hyperplane that is not the optimal separating hyper- plane, and provide the equation for this hyperplane. - viii. Draw an additional observation on the plot so that the two classes are no longer separable by a hyperplane.