title: Building a RandomForest with caret
body: <p>I was attempting to build a RandomForest model in caret following the steps <a href="https://www.guru99.com/r-random-forest-tutorial.html" rel="nofollow noreferrer">here</a>.  Essentially, they set up the RandomForest, then the best mtry, then best maxnodes, then best number of trees.  These steps make sense, but wouldn't it be better to search the interaction of those three factors rather than one at a time?</p>
  
  <p>Secondly, I understand performing a grid search for mtry and ntrees. But I do not know what to set the minimum number of nodes or maximum number of nodes at. Is it generally advisable leave the default nodesize as shown below?</p>
  
  <pre><code>library(randomForest)
  library(caret)
  mtrys&lt;-seq(1,4,1)
  ntrees&lt;-c(250, 300, 350, 400, 450, 500, 550, 600, 800, 1000, 2000)
  combo_mtrTrees&lt;-data.frame(expand.grid(mtrys, ntrees))
  colnames(combo_mtrTrees)&lt;-c('mtrys','ntrees')
  
  tuneGrid &lt;- expand.grid(.mtry = c(1: 4))
  for (i in 1:length(ntrees)){
    ntree&lt;-ntrees[i]
    set.seed(65)
    rf_maxtrees &lt;- train(Species~.,
                         data = df,
                         method = "rf",
                         importance=TRUE,
                         metric = "Accuracy",
                         tuneGrid = tuneGrid,
                         trControl = trainControl( method = "cv",
                                                   number=5,
                                                   search = 'grid',
                                                   classProbs = TRUE,
                                                   savePredictions = "final"),
                         ntree = ntree
                         )
    Acc1&lt;-rf_maxtrees$results$Accuracy[rf_maxtrees$results$mtry==1]
    Acc2&lt;-rf_maxtrees$results$Accuracy[rf_maxtrees$results$mtry==2]
    Acc3&lt;-rf_maxtrees$results$Accuracy[rf_maxtrees$results$mtry==3]
    Acc4&lt;-rf_maxtrees$results$Accuracy[rf_maxtrees$results$mtry==4]
    combo_mtrTrees$Acc[combo_mtrTrees$mtrys==1 &amp; combo_mtrTrees$ntrees==ntree]&lt;-Acc1
    combo_mtrTrees$Acc[combo_mtrTrees$mtrys==2 &amp; combo_mtrTrees$ntrees==ntree]&lt;-Acc2
    combo_mtrTrees$Acc[combo_mtrTrees$mtrys==3 &amp; combo_mtrTrees$ntrees==ntree]&lt;-Acc3
    combo_mtrTrees$Acc[combo_mtrTrees$mtrys==4 &amp; combo_mtrTrees$ntrees==ntree]&lt;-Acc4
  }
  </code></pre>