
Random Forests and Feature Subsampling
Random forests combine many decision trees, each trained on a bootstrap sample and split on random feature subsets. Averaging reduces variance, and out-of-bag checks give a practical accuracy estimate.
स्रोत
पूरा पाठ सारांश
A random forest grows many decision trees, and each tree sees a slightly different world. First, the training data are resampled with replacement to form a bootstrap sample of the same size as the original. If a class has 120 students, a bootstrap sample also has 120 rows, but some students appear twice or three times while others are left out. Second, at every split the tree considers only a random subset of candidate features, chosen separately at each node. In scikit-learn's RandomForestClassifier the default max_features is "sqrt", so with 16 features each split inspects about 4 of them. Resampling rows and subsampling columns together produce trees whose errors are somewhat decoupled.
Correlation among trees is the key concern. If every tree saw the same rows and the same dominant feature, all trees would make nearly the same mistakes, and averaging would barely help. Suppose a forest of 101 trees classifies a new example. Ninety trees vote "high risk" and eleven vote "low risk". A majority vote returns high risk. scikit-learn's classifier instead averages each tree's predicted class probabilities and takes the largest average, which can differ from the majority vote when trees are confident or uncertain in uneven ways. These two rules are not the same and should not be described interchangeably.
More randomness is not automatically better. Setting max_features very small can leave each split with weak candidates, so individual trees underfit and the forest needs more trees to recover. The balanced setting is found by cross-validation, not assumed. Consider a forest where max_features is 1 and the best predictor is unavailable at the root. Trees may split on noise, and individual predictions may deteriorate enough to outweigh the benefit of averaging across different trees.
Out-of-bag checking uses the rows each tree never saw. With bootstrap=True and oob_score=True, scikit-learn records, for every training row, predictions only from trees whose bootstrap sample excluded that row, then scores those predictions. This gives an accuracy estimate without a separate holdout set, though it is not a substitute for testing on genuinely new data.
Give pairs a small table of 12 hypothetical students with four features and a pass/fail label. Each pair draws a bootstrap sample, marks excluded rows, and at each split rolls a die to choose two candidate features. Build three trees on the board, then compare a majority vote with an averaged-probability prediction for one new student. Ask pairs to explain in writing why their trees disagree and which rows were out-of-bag. Collect the explanations and read two aloud, asking the class to identify where randomness entered and where correlation would have hurt the vote.
Trace one disputed result back through the three trees to see which change in rows or candidate features altered its prediction.


