What are the main hyperparameters of a Random Forest and what does each control?
Last updated
Random Forest hyperparameters fall into three groups: ensemble size, the randomness that decorrelates trees, and the complexity limits on each tree. Names below follow scikit-learn.
Ensemble size:
n_estimators: number of trees.More trees lower variance until the error plateaus. Past that point they only cost compute and do not overfit.
Randomness and decorrelation:
max_features: number of features considered at each split. This is the most important knob, because it trades tree strength against correlation.bootstrap/max_samples: whether each tree trains on a resample, and how large that resample is.
Tree complexity (regularization):
max_depth,max_leaf_nodes: cap the size of each tree.min_samples_split,min_samples_leaf: the minimum number of samples needed to split a node or to form a leaf. These smooth predictions.min_impurity_decrease: a split happens only if it improves impurity by at least this amount.
Split quality and class handling:
criterion: the impurity measure. Classification usesginiorentropy; regression usessquared_errorand similar.class_weight: reweights classes when the data is imbalanced.
Utility settings (do not change the model's capacity):
oob_score: computes a free validation estimate from out-of-bag samples.n_jobs: parallelism.random_state: reproducibility.
- https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html
- https://www.geeksforgeeks.org/machine-learning/hyperparameters-of-random-forest-classifier/
- https://medium.com/@kalpit.sharma/mastering-random-forest-hyperparameter-tuning-for-enhanced-machine-learning-models-2d1a8c6c426f