Question: Hello, I solved (a),(b) but struggling with (c), (d), (e) in R. Could you explain it in R please? Data: y

Hello, I solved (a),(b) but struggling with (c), (d), (e) in R. Could you explain it in R please?

Data:

y<-runif(1000,min=0, max=23) x1<-runif(1000, min=-3, max=5) x2<-runif(1000, min=-3, max=5) x3<-runif(1000, min=-3, max=5) x4<-runif(1000, min=-3, max=5) x5<-runif(1000, min=-3, max=5) x6<-runif(1000, min=-3, max=5) x7<-runif(1000, min=-3, max=5) x8<-runif(1000, min=-3, max=5) x9<-runif(1000, min=-3, max=5) x10<-runif(1000, min=-3, max=5) df.train<-data.frame(y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)

(a) Split the data into a training set with 900 observations and a test set with the remaining observations.

my solution:

to <- sample(1:nrow(df.train), 900) train<-df.train[to,] test<-df.train[-to,]

(b) Build a random forest with the training data; call it rf

my solution

library(randomForest) rf <- randomForest(y~.,data=train, importance = TRUE)

(c) Now let's explicitly test how important each predictor is using the permutation idea. Use a for loop so that the i th time through the loop, you permute the values of the i th predictor, rebuild the random forest, predict on the test set and record the MSE. Call the vector of MSEs mse.perm.

(d) Repeat part (c) but instead of permuting the i th predictor on the i th iteration, simply remove it from the data frame, rebuild the random forest, predict on the test set and calculate the MSE. Call this vector of MSEs mse.loo and create the same plot as above. Do these MSEs look more like those in part (b) or more like those in part (c)? Which would you trust more?

(e) Explore the original data and see if you can determine what might be causing the difference you see. Pay close attention to those variables that are receiving the most different importance scores.

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!