CV in random forest: error.cv is 0


#1

While trying to do cross validation in R: I am getting error.cv =0

rfcvtest <- rfcv(traindata, traindata$Ind ,cv.fold = 5)

Any help is appreciated.

Thanks,
Soumya


#2

Hi Soumya,

Please take a look at the code below:

rf <-rfcv(iris, iris$Species, cv.fold=5)
#Capture the error rates:
rf.error <- rf$error.cv
#Take the predicted values at each fold:
rf.cv.1 <- rf$predicted$`1`
#Compare with original data:
table(iris$Species,rf.cv.1)

rf.cv.2 <- rf$predicted$`2`
table(iris$Species,rf.cv.2)

rf.cv.5 <- rf$predicted$`5`
table(iris$Species,rf.cv.5)

The outputs:

As you can see in the first output for cv = 2 the number of miss-classified cases is just 7 out of 150 which gives an error rate of 0.0467,whereas if you take a look at the last output,all the classes have been correctly classified and that is why the error.cv is coming out to be zero.
the error.cv is a vector that captures the error rate at each step.
I beleive in your case the accuracy is 100% when cv.folds = 5.
Hope this helps!!


#3

Thanks Shuvayan for the explanation.
I had not checked for confusion matrix at each step. Indeed the classes seems to be correctly classified at each step.