ML0065 Random Forest III

How to choose the number of features in a random forest?

Answer

Select the number of features considered at each split (the m, or max_features) by starting from the default heuristics, then tuning with cross-validation or out-of-bag (OOB) error to find the best value for your specific dataset. The choice trades bias against variance and accuracy against training cost.

(1) Default Heuristics: Classification: m = \sqrt{p}; regression: m = p/3; solid starting points.
(2) Bias-Variance Trade-Off: Smaller m adds randomness: less correlated trees (lower variance) but potentially higher bias; larger m strengthens each tree (lower bias) but correlates their errors (higher variance).
(3) Systematic Search: Grid or randomized search over a range of values with cross-validation is the most robust method; OOB error offers a validation-free alternative unique to bagged models.

Cross validation accuracy versus max features from 1 to 30 with a noisy plateau peaking at 15

Figure 1: CV accuracy across max_features on a 30-feature dataset: accuracy is poor when m is tiny (trees too weak), then plateaus with a noisy peak at m = 15; the \sqrt{p} \approx 5.5 heuristic lands inside the good region, and CV refinement picks the best value on the plateau.

Mathematical Formulation:
m = \sqrt{p} \quad \text{(classification)}
m = \frac{p}{3} \quad \text{(regression)}

Where:

  • p is the total number of features in the dataset.
  • m is the number of features randomly drawn and considered at each split (max_features in most libraries).
  • These are heuristics, not optima; cross-validation or OOB error refines them per dataset.

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *