3 Forêts aléatoires
3.1 Principe général
3.1.1 Instabilité d’un arbre
set.seed(368910)
spamBoot1 <- spamApp[sample(1:nrow(spamApp), nrow(spamApp), replace = TRUE), ]
treeBoot1 <- rpart(type ~ ., data = spamBoot1)
plot(treeBoot1)
text(treeBoot1, xpd = TRUE)
3.3 Le package randomForest
3.5 Réglage des paramètres pour la prédiction
3.5.1 Le nombre d’arbres ntree
3.5.2 Le nombre de variables choisies à chaque noeud 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"])})