Random Forest Overfitting R I used a two-step cforest in my model. the accuracy of the train set is 87%, yet the accuracy of the test set is 57%. This indicates the model is severely overfitting. How to solve this problem? Should I reduce the nodes of the tree or divide the data into k fold? How can I determine how many nodes should I retain?
Here is the code for step 1.
   fit1 <- cforest((b == 'three')~ posemo + social + family
            +friend + home + humans + money + they
            + social+article+certain+insight+affect+ negemo+ future+swear+sad
            +negate+ppron+sexual+death + filler+leisure, data = trainset1, 
            controls=cforest_unbiased(ntree=3000, mtry= 3))

 A: One reason that you Random Forest may be overfitting may be because you have a lot of redundant features or your features are heavily correlated.
If lot of your features are redundant, then when you perform the splits in the nodes of the trees, the algorithm may often only choose very poor features, which makes your model just chase some noise in your data.
It is wise to look at the variable importance of the forest to try to identify if you have features that are maybe not relevant.
You can also try to make some dimensionality-reduction/aggregation on the features.
A: 
In random forests, overfitting is generally caused by over growing the
  trees

as stated in one of the other answers is completely WRONG. The RF algorithm, by definition, requires fully grown unprunned trees. This is the case because RF can only reduce variance, not bias (where $error=bias+variance$). Since the bias of the entire forest is roughly equal to the bias of a single tree, the base model used has to be a very deep tree to guarantee a low bias. Variance is subsequently reduced by growing many deep, uncorrelated trees and averaging their predictions.
I wouldn't necessarily say that a training accuracy of 87% and a test accuracy of 57% indicates severe overfitting. Performance on your training set will always be higher than on your test set. Now, you need to provide more information if you want CV users to be able to diagnose the source of your potential overfitting problem.


*

*how did you tune the parameters of your random forest model? Did you use cross-validation, or an independent test set? What are the sizes of your training/testing sets? Did you properly used randomization to constitute these sets?

*is your target categorical or continuous? If yes to the former, do
you have any kind of class imbalance issue?

*how did you measure error? If it applies, is your classification problem binary, or multiclass?


In practice, Random Forest seldom overfit. But what would tend to favor overfitting would be having too many trees in the forest. At some point it is not necessary to keep adding trees (it does not reduce variance anymore, but can slightly increase it). This is why the optimal number of trees should be optimized like any other hyperparameter (or at least, should not be carelessly set to too high of a number. It should be the smallest number of trees needed to achieve lowest error. You can look at a plateau in the curve of OOB error VS number of trees).
Other than overfitting, the difference in accuracy between train & test that you observe could be explained by differences between the sets. Are the same concepts present in both sets? If not, even the best classifier won't be able to perform well out-of-bag. You can't extrapolate for something if you did not even learn about some aspect of it.
I would also recommend that you read the section about RF in the formative Elements of Statistical Learning. Especially, see section 15.3.4 (p. 596) about RF and overfitting.
A: In random forests, overfitting is generally caused by over growing the trees.
Pruning the trees would also help.
So, some parameters which you can optimize in the cForest argument are the ntree, mtry
mtry is the number of variables the algorithm draws to build each tree.
ntree is the total number of trees in the forest.
Having said that, cross validation always helps. Consider carrying out k-fold cross validation. This forum on Kaggle would help understand carrying out cross validation in random forests.
