Random Forest

A random forest is an ensemble of decision trees trained on bootstrap samples of the data, with random feature subsets at each split. Final predictions aggregate trees by majority vote (classification) or averaging (regression).

Intuition

A single tree captures nonlinear interactions but overfits easily (high variance). Random forest applies bagging: train many trees on different subsamples and average them to reduce variance without increasing bias as much.

Randomizing features at each split decorrelates trees — a necessary condition for aggregation to genuinely improve generalization over one deep tree.

How it works

  1. Bootstrap

    : for each tree , draw observations with replacement from (about 63% unique observations per tree).

  2. Unpruned tree: grow until depth or stopping criteria (max_depth, min_samples_leaf, etc.).

  3. Random subspace

    : at each node, consider only a subset of max_features variables for the best split.

  4. Aggregation: classification → majority class; regression → mean of tree predictions.

Out-of-bag (OOB) score: observations not in a tree's bootstrap sample act as an implicit validation set. With oob_score=True, you get a performance estimate without a dedicated validation set — useful for prototyping, but not a substitute for rigorous cross-validation.

Key hyperparameters

ParameterRoleTypical values
n_estimatorsNumber of trees in the forest100–500; diminishing returns beyond
max_depthMaximum depth of each tree

None (unlimited) or 10–30 depending on noise

min_samples_leafMinimum leaf size1–10; higher = more regularization
min_samples_splitMinimum samples to split a node2 (default) to 20+ on noisy data
max_featuresCandidate variables per split

sqrt (classif.), 1/3 (regression); decorrelates trees

bootstrapSampling with replacement

True (default); False → each tree sees all data

oob_scoreOut-of-bag evaluation

True when bootstrap=True

class_weightClass imbalance weighting

balanced or weight dictionary

n_jobsParallel training

-1 for all cores

Strengths and limitations

Strengths

  • Robust to outliers and feature scales (no mandatory normalization)
  • Captures interactions and nonlinearities without explicit feature engineering
  • Built-in feature importance; free OOB score
  • Parallelizable; relatively few critical hyperparameters

Limitations

  • Less interpretable than a single tree
  • Memory and latency grow with n_estimators
  • Regression: poor extrapolation outside the training domain
  • Can be outperformed by gradient boosting on structured tabular data
  • Sensitive to concept drift and non-iid data without adaptation
ModelPrinciplevs Random Forest
Decision treeSingle tree, deterministic splitsMore interpretable, much higher variance
Extra TreesRandom splits (random thresholds among candidates)More decorrelation, often faster, sometimes slightly less accurate
Gradient Boosting (XGBoost…)Sequential trees fitting residuals

Often better on tabular competitions; more tuning-sensitive and overfit-prone

Logistic / linear regressionLinear modelFast interpretable baseline; misses complex interactions
k-NNLocal neighborhoodMetric- and dimension-sensitive; high prediction latency

Evaluation and tuning

StepRecommendation
Data splitting

Train / validation / test; for time series: walk-forward or purged CV — see cross-validation

Metrics

Classification: accuracy, F1, ROC AUC, log loss by business cost; regression: RMSE, MAE,

Hyperparameter search

Start with n_estimators and max_depth; refine min_samples_leaf and max_features via grid or random search

OOB

Quick indicator during prototyping; validate on hold-out or CV before deployment

Overfitting

Increase min_samples_leaf, reduce max_depth; check train/validation gap

Feature importance

MethodPrincipleLimits
Impurity (Gini / MSE)

Mean impurity decrease per feature across trees (feature_importances_)

Biased toward high-cardinality features; correlated features
Permutation importancePerformance drop when a feature is randomly permutedMore reliable; higher compute cost
SHAPShapley values per observation and feature

Local and global interpretation — see ML for markets

Applications

I will add concrete, precise examples in the future.

References