Random Forest

From Bitnami MediaWiki
Revision as of 02:28, 23 March 2021 by User (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Random Forests reduce the variance of a Decision Tree or other CART (Classification And Regression Trees) model by averaging together multiple estimates from individual Decision Trees. Trees are trained on a random subset of features and data cases. (Microsoft's Kinect body motion detector used a Random Forest.) Trees are often "bagged" (bootstrap aggregated). In a bootstrap, samples are drawn at random with replacement to produce more training data than exist.

The Bootstrap

The bootstrap is "a simple Monte Carlo technique to approximate the sampling distribution" (Murphy, p.192), especially useful when the estimator is a complex function of the parameters. The estimate is (Hastie et al., p.250):

[math]\displaystyle{ \widehat{\text{Err}}_\text{boot} \dfrac{1}{B}\dfrac{1}{N}\sum^B_{b=1}\sum^N_{i=1}L(y_i, \hat{f}^{*b}(x_i)) }[/math]

However, this expression will be zero unless the ith observation does not appear in the bootstrap sample [math]\displaystyle{ b }[/math]

[math]\displaystyle{ \text{Pr\{observation } i \in \text{ bootstrap sample } b\} = 1 - \left(1-\dfrac{1}{N} \right)^N \approx 1-e^{-1} = 0.632 }[/math]
  • This is a problem because the baseline expectation is about 0.184 (0.5 x 0.368), well short of 0.5.
  • The leave-one-out bootstrap mimics cross-validation in that it only uses a prediction not containing the actual observation. This solves the overfitting problem but retains the train-set-size bias present in cross-validation.
  • The parametric bootstrap

Sklearn parameters

n_estimators=100
criterion='gini'
max_depth=None
min_samples_split=2
min_samples_leaf=1
min_weight_fraction_leaf=0.0
max_features='auto'
max_leaf_nodes=None
min_impurity_decrease=0.0
min_impurity_split=None
bootstrap=True
oob_score=False
class_weight=None

Parameter Settings

Param Default Description
n_estimators 100 number of trees in forest
criterion mse mse or mae
max_depth None max depth of tree; if none, nodes expand until all leaves are pure
min_samples_split 2 min samples needed to split internal nodes; floats allowed
min_samples_leaf 1 min samples needed to be at a leaf node;
if int: min_samples_leaf is the min
if float: ceil(min_samples_leaf*n_samples) is the min
min_weight_fraction_leaf 0.0 min weighted fraction of total weights required to be at a leaf node
max_features auto n_features; also 'sqrt', 'log2'
min_impurity_decrease 0.0 threshold for splitting a node
warm_start false True reuses solution of previous "fit" call to add more estimators
ccp_alpha 0.0 parameter for Minimal Cost-Complexity Pruning
max_samples None If bootstrap=True (default) num samples to draw from X; range(0,1)