My current data set has about 900 records & 10 features. I am trying to use random forest to classify some data. My current model is terribly over fitting the data hence I am trying to use the rfcv function. I am having some trouble understanding the output of this function.

Here is some sample code

data(fgl, package="MASS")
tst <- rfcv(trainx = fgl[,-10], trainy = fgl[,10], scale = "log", step=0.7)

I can print some output from this but I am not sure how to interpret this?

        9         6         4         3         2         1 
0.2102804 0.2196262 0.2429907 0.2523364 0.3551402 0.5607477 

I also have the log of the importance function

RI        23.358203
Na        15.901377
Mg        25.923452
Al        24.587295
Si        12.586816
K         13.731823
Ca        19.680839
Ba        14.206922
Fe         6.774196

1 Answer 1


The rfcv function creates multiple models based on the number of predictors and the "step" argument (default = 0.5). In your case you began with 9 predictors with step = 0.7 which corresponds to the first row in your output

  • first value = 9,
  • second value = round(9(0.7)) = 6,
  • third value = round(6(0.7)) = 4, and so on.

So the first row of the output is just the number of predictors used in each model. The second row in your output is the cross-validation error of each of the models. It becomes clear that as the number of predictors are reduced the error generally increases, but the difference between using 9 predictors and using 6 predictors is low which suggests the 6 predictor model is about as good as the 9 predictor model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.