FINA6609 Problem Set 1
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
FINA6609 Problem Set 1
Due: April 6, 11:59pm
In this and future assignments, you may be asked to use additional R packages or functions. Recall that, for any function f which you are unsure of the usage about, you may type ?f in the R console to obtain the help file for that function, or ??f to perform a search.
For the assignment, submit only the problems marked by *. While unmarked problems are not required to be submitted, they may be useful for improving your mastery over the material.
Please go through the coding labs in ISLR2 before attempting the coding questions. Rmd files for the labs can be found in the relevant course content folders.
These questions are adapted from section 8.4 of the ISLR2 textbook.
1. (Adapted from question 4 of ISLR2) This question relates to the below plots.
(a) Sketch the tree corresponding to the partition of the predictor space illustrated in the left-hand panel of the figure. The numbers inside the boxes indicate the mean of Y within each region.
(b) Create a diagram similar to the left-hand panel of Figure 8.14, using the tree illustrated in the right-hand panel of the same figure. You should divide up the predictor space into the correct regions, and indicate the mean for each region.
2. (Adapted from question 7 of ISLR2) The lab demonstrates how to apply random forests to the Boston data using mtry =6 and using ntree = 25 and ntree = 500. Mimicking Figure 8.10, create a plot displaying the test error resulting from random forests on this data set for a more comprehensive range of values for mtry and ntree. Describe the results obtained.
3. *(Adapted from question 9 of ISLR2) This problem involves the OJ data set which is part of the ISLR2 package.
(a) Create a training set containing a random sample of 900 observations, and a test set containing the remaining observations. Set the seed to 100 to ensure replicability.
(b) Fit a tree to the training data, with Purchase as the response and the other variables as predictors. Use the summary() function to produce summary statistics about the tree, and describe the results obtained. What is the training error rate? How many terminal nodes does the tree have?
(c) Type in the name of the tree object in order to get a detailed text output. Pick one of the terminal nodes, and interpret the information displayed.
(d) Create a plot of the tree, and interpret the results.
(e) Predict the response on the test data, and produce a confusion matrix comparing the test labels to the predicted test labels. What is the test error rate?
(f) Apply the cv.tree() function to the training set in order to determine the optimal tree size.
(g) Produce a plot with tree size on the x-axis and cross-validated classification error rate on the y-axis.
(h) Which tree size corresponds to the lowest cross-validated classification error rate?
(i) Produce a pruned tree corresponding to the optimal tree size obtained using cross-validation. If cross-validation does not lead to selection of a pruned tree, then create a pruned tree with five terminal nodes.
(j) Compare the training error rates between the pruned and unpruned trees. Which is higher? (k) Compare the test error rates between the pruned and unpruned trees. Which is higher?
4. *The following output is generated by printing a given tree object in R. Sketch the tree corresponding to the following output. (Note: it will be helpful to use a previously plotted tree as reference.)
> mytree
node), split, n, deviance, yval
* denotes terminal node
1) root 490 30250 .0 21 .64
2) lstat < 9 .725 196 9703 .0 28 .07
4) rm < 6 .797 126 1571 .0 24 .17
8) rm < 6 .543 87 753 .7 22 .90 *
9) rm > 6 .543 39 364 .2 27 .00 *
5) rm > 6 .797 70 2744 .0 35 .11
10) rm < 7 .437 51 729 .5 32 .45 *
11) rm > 7 .437 19 681 .3 42 .26 *
3) lstat > 9 .725 294 7006 .0 17 .34
6) lstat < 16 .085 150 1627 .0 20 .30 *
7) lstat > 16 .085 144 2699 .0 14 .26
14) lstat < 19 .9 69 898 .2 16 .37 *
15) lstat > 19 .9 75 1214 .0 12 .33 *
5. *(Adapted from question 8 in the textbook) In the lab, a classification tree was applied to the Carseats data set after converting Sales into a qualitative response variable. Now we will seek to predict Sales using regression trees and related approaches, treating the response as a quantitative variable.
(a) Split the data set into a test set consisting of 20% of the data, and 80% training. Set the seed to 100 for replicability.
(b) Fit a regression tree to the training set. Plot the tree, and interpret the results. What test MSE do you obtain?
(c) Use cross-validation in order to determine the optimal level of tree complexity. Does pruning the tree improve the test MSE?
(d) Use the bagging approach in order to analyze this data. What test MSE do you obtain? Is this an improvement over a single regression tree? Use the importance() function to determine which variables are most important.
(e) Use random forests to analyze this data. What test MSE do you obtain? Is this an improvement over bagging? Use the importance() function to determine which variables are most important.
6. *(Adapted from question 10 in the textbook) We now use boosting to predict Salary in the Hitters data set.
(a) Remove the observations for whom the salary information is unknown, and then log-transform the salaries.
(b) Create a training set consisting of the first 200 observations, and a test set consisting of the remaining observations.
(c) Perform boosting on the training set with 1,000 trees for a range of values of the shrinkage parameter λ . Produce a plot with different shrinkage values on the x-axis and the corresponding training set MSE on the y-axis.
(d) Produce a plot with different shrinkage values on the x-axis and the corresponding test set MSE on the y-axis.
(e) Which variables appear to be the most important predictors in the boosted model?
2023-04-07