hw-9

Homework 9 in DSCI445: Statistical Machine Learning @ CSU

Assignment

Be sure to set.seed(445).

  1. This problem involves the \(OJ\) data set in the \(ISLR\) package.

    1. Create a training set containing a random sample of \(800\) observations and a test set containing the remaining observations.

    2. Fit a tree to the training data with Purchase as the response and the other variables as predictors. Describe the results obtained. What is the training error rate? How many terminal nodes does the tree have?

    3. Create a plot of the tree and interpret.

    4. Predict the response on the test data and produce a confusion matrix comparing the test labels to the predicted labels. What is the test error rate?

    5. Apply the cross validation to the training set in order to determine the optimal tree size.

    6. Produce a plot with complexity on the x-axis and CV error rate (or CV accuracy) on the y-axis. Which tree size corresponds to the lowest CV classification error rate?

    7. Produce a pruned tree corresponding to the optimal tree size. If CV doesn’t lead to the selection of a pruned tree, then create a pruned tree with five terminal nodes.

    8. Compare the training error rates between the pruned and unpruned tree.

    9. Compare the test error rates between the pruned and unpruned tree.

  2. We will use boosting, bagging, and random forests to predict Salary in the Hitters data set.

    1. Remove the observations for which the salary information is unknown and then log-transform the salaries.

    2. Create a training set consisting of the first \(200\) observations and a test set consisting of the remaining observations.

    3. Perform boosting on the training set with \(1,000\) trees for a range of values of the shrinkage parameter \(\lambda\). Produce a plot with different shrinkage values on the \(x\)-axis and the corresponing training MSE on the \(y\)-axis.

    4. Produce a plot with different shrinkage values on the \(x\)-axis and the corresponing test MSE on the \(y\)-axis.

    5. Compare the test MSE of boosting to the test MSE that results from two other regression approaches (Something from Ch. 3, 6, or 7)

    6. Which variables appear to be the most important predictors in the boosted model?

    7. Now apply bagging to the training data set. What is the test MSE for this approach?

    8. Now apply random forest to the training data set. What is the test MSE for this approach?

Turn in in a pdf of your homework to canvas using the provided Rmd file as a template. Your Rmd file on the server will also be used in grading, so be sure they are identical.

Be sure to share your server project with the instructor and grader. You only need to do this once per semester.

  1. Open your homeworks project on liberator.stat.colostate.edu

  2. Click the drop down on the project (top right side) > Share Project…

  3. Click the drop down and add “dsci445instructors” to your project.

This is how you receive points for reproducibility on your homework!