Question: ISLR, chapter 8, problem 8 Use R with RStudio (a) Split the data set into a training set and a test set. (b) Fit a

ISLR, chapter 8, problem 8

Use R with RStudio

(a) Split the data set into a training set and a test set.

(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? 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? Use the importance() function to determine which variables are most important. Describe the effect of m, the number of

variables considered at each split, on the error rate

obtained.

For part (a), use the following split into training and test sets.

```{r}

set.seed(44182)

library(ISLR)

library(randomForest)

attach(Carseats)

n=nrow(Carseats)

indices=sample(1:n,n/2,replace=F)

cstrain=Carseats[indices,]

cstest=Carseats[-indices,]

```

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!