[R] randomForest set.seed()

Joao Carreiras j.carreiras at sheffield.ac.uk
Thu Jul 9 15:06:30 CEST 2015


Dear forum members,

​I wrote a piece of code to test various combinations of mtry and ntree, so
that the best combination (in terms of mse​) could be used. Before each
randomForest command I included a set.seed() command, so that I can keep
track of the seed number and replicate the results. However, when I run the
randomForest command again with the seed number corresponding to the best
combination I get a different mse. Any suggestions?
Thanks and best wishes
Joao

------------
## Define the number of trees to test
nt <- c(100, 200, 300, 400, 500, 700, 900, 1000)
## Define the number of variables to be randomly selected at each node
mt <- c(1, 2, 3)
##
a <- 0
##
## For loop to test the various combinations of ntree and mtry
for (j in 1:8)
   for (i in 1:3)
​ ​
{
         b <- 1968 + a
         set.seed(b)
         HH <- randomForest(HH_MEAN ~ ASF + PALU + FC
​​
,
​​
                            data = model.data,
                            ntree = nt[j],
                            mtry = mt[i],
                            replace = T,
​                     ​
​ }​
​----------------​

​​

	[[alternative HTML version deleted]]



More information about the R-help mailing list