# What should be the optimal parameters for Random Forest classifier?

Currently i am using RF toolbox on MATLAB for a binary classification Problem

Data Set: 50000 samples and more than 250 features

So what should be the number of trees and randomly selected feature on each split to grow the trees? can any other parameter greatly affect the results?

Pick a large number of trees, say 100. From what I have read on the Internet, pick $\sqrt{250}$ randomly selected features. However, in the original paper, Breiman used about the closest integer to $\frac{\log{M}}{\log{2}}$.

I would say cross-validation is usually the key to finding optimal parameters, but I do not know enough about random forests.

• Breiman used $\lfloor 1 + \log_2 M\rfloor$ features. I am leaving a comment here, because your link does not work:) May 10, 2017 at 11:26
• Thanks, I have updated the link. Now, it is direct to Berkeley.
– Wok
May 31, 2017 at 8:44

Number of trees the bigger, the better. You almost can't overshoot with this parameter, but of course the upper limit depends on the computational time you want to spend on RF.
The good idea is to make a long forest first and then see (I hope it is available in MATLAB implementation) when the OOB accuracy converges.

Number of tried attributes the default is square root of the whole number of attributes, yet usually the forest is not very sensitive about the value of this parameter -- in fact it is rarely optimized, especially because stochastic aspect of RF may introduce larger variations.

Number of trees the bigger, the better : agreed.

Number of tried attributes will depend. If you already have some a priori about the way the information is spreading or not among the features. If the information is shared by many features, better results would come up with smaller value of that parameter. While, on the other hand, if only a few features are carrying the information, you should use larger values. In other words, with many relevant variables : smaller values are better and with many irrelevant variables : bigger values are better.

• Whilst your claim about number of tried attributes makes sense, do you have a citation for this? Sep 4, 2015 at 13:08
• I would recommend reading this thesis: github.com/glouppe/phd-thesis as well as this one: orbi.ulg.ac.be/handle/2268/25737
– 0asa
Apr 12, 2017 at 9:03