title: Automatically tunes Random Forest
body: <p>I want to automatically tune the Random Forest Model as my variables keeps on changing on real time basis. I am using the <code>iris</code> dataset. </p>
  
  <p>My code is </p>
  
  <pre><code>jk = iris
  
  library(randomForest)
  library(caret)
  
  fgl.res &lt;- tuneRF(lm[,-5], lm[,5], stepFactor=1.5)
  
  o/p:
  mtry = 2  OOB error = 5.33% 
  Searching left ...
  Searching right ...
  mtry = 3    OOB error = 4% 
  0.25 0.05 
  mtry = 4    OOB error = 5.33% 
  -0.3333333 0.05 
  </code></pre>
  
  <p>Above I want that in <code>fgl.res</code> code it automatically chooses the <code>Species</code> column index i.e. 5 in <code>iris</code> dataset and insert in <code>fgl.res</code> code.</p>
  
  <p>Then to use a first line of <code>fgl.res</code> output(o/p) and takes value of <code>"mtry = 2  OOB error = 5.33% "</code> and use it in random forest code, i.e. assign value to <code>mtry</code> and <code>oob.error</code> as shown below:</p>
  
  <pre><code>mod2&lt;-randomForest(Species~., data=lm, ntree=50, mtry=2, oob.error=0.0533)
  </code></pre>
  
  <p>I have tried many ways but nothing work out on how to automatically insert value into code from <code>fgl.res</code> output.</p>