I am trying to use a random forest model in R

RF<- randomForest(as.factor(y)~., data=train, importance=TRUE, proximity=FALSE, 
                                              ntree=1000, keep.forest=TRUE)

Y is binary. Model runs without any issues. However i have some questions

I have about 50,000 rows of data and 300 variables. As per other theards using proximity=TRUE will likely run very slow or requires a lot of memory.

  1. Using proximity=TRUE will it give me different results if memory was not an issue ?
  2. I am interested in probability of predicting my 1s as my final outcome. when i do predicted=predict(RF)..i get 1's and 0s are my prediction. I would rather like probabilites.
  3. How do we implement a random forest model ? I have 1000 trees. If i want to implement this model real time, how do we code this ? Do we code 1000 decision trees to make prediction for each new case ?

Thank you.

  • $\begingroup$ You might find this answer helpful: stats.stackexchange.com/questions/21152/… $\endgroup$
    – user3490
    Commented Jul 14, 2013 at 19:32
  • $\begingroup$ The selected answer at that link is somewhat misleading. While you do get many diagnostic tools with RF, you can only get a plot like the one shown if your RF is fitted using only stumps. This is because the plot assumes the model is additive in the predictors, which will not be true if the base trees are more complex. $\endgroup$
    – Hong Ooi
    Commented Jul 15, 2013 at 3:18

1 Answer 1

  1. No, changing the proximity argument won't change the result per se. However, since RF is a stochastic algorithm you'll get a different model if you run it again, because its random draws will be different. If you don't want this behaviour, be sure to set the random seed with set.seed before each run of randomForest.

  2. To get predicted probabilities, use type="prob" in your call to predict. You'll get a matrix, which is the probability of each case being a 0 or a 1.

  3. Yes, potentially you have to code 1000 individual trees if you're re-implementing the model logic elsewhere. This is where in-database implementations of R are very handy: you can actually run your RF model in the database (or import it), and keep the fitted model object around.

  • $\begingroup$ Thank you very much for your help. For item 3 do we have any example anywhere I can look at ? How do we even save the 1000 trees ? and how can we look at what is inside those 1000 trees ? what is in-database implementation ? any example would greatly help me implement this model. Thank you $\endgroup$
    – user16789
    Commented Jul 14, 2013 at 19:15
  • $\begingroup$ An example for point 3 is available here: stackoverflow.com/questions/7863942/save-a-random-forest-object $\endgroup$
    – user3490
    Commented Jul 14, 2013 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.