3.5.2 The number of variables chosen at each node: mtry
nbvars <- 1:(ncol(spamApp) - 1)
oobsMtry <- sapply(nbvars, function(nbv) {
RF <- randomForest(type ~ ., spamApp, ntree = 250, mtry = nbv)
return(RF$err.rate[RF$ntree, "OOB"])
})
mean(replicate(n = 25, randomForest(type ~ ., spamApp, ntree = 250)$err.rate[250,
"OOB"]))
bagStump <- randomForest(type ~ ., spamApp, ntree = 100, mtry = ncol(spamApp) - 1,
maxnodes = 2)
bagStumpbestvar <- table(bagStump$forest$bestvar[1, ])
names(bagStumpbestvar) <- colnames(spamApp)[as.numeric(names(bagStumpbestvar))]
sort(bagStumpbestvar, decreasing = TRUE)
RFStump <- randomForest(type ~ ., spamApp, ntree = 100, maxnodes = 2)
RFStumpbestvar <- table(RFStump$forest$bestvar[1, ])
names(RFStumpbestvar) <- colnames(spamApp)[as.numeric(names(RFStumpbestvar))]
sort(RFStumpbestvar, decreasing = TRUE)