I'm using the R package randomForest
. When you fit a model, it outputs the confusion matrix, but this completely mismatches what I find when I calculate the confusion matrix based on majority vote myself, using the model predictions. According to the documentation, the default is to use majority vote as the cutoff for classification, so I can't make sense of this.
Here is an example:
require(randomForest)
set.seed(1)
y <- runif(500)<.5
x <- matrix(rnorm(5000),500,10)
z <- cbind(y,x)
colnames(z) <- c("y",paste("x",c(1:10),sep=""))
rfm <- randomForest( as.factor(y) ~ ., data=z )
rfm$confusion
0 1 class.error
0 81 149 0.6478261
1 101 169 0.3740741
pred <- predict(rfm, z, type="vote", norm.votes=FALSE)[,2]
table(pred>250,y) # there are 500 trees, so >250 is a majority
y
FALSE TRUE
FALSE 230 0
TRUE 0 270
Any clue what is going on here?