Bootstrap sampling forms each training sample by selecting observations from the original training data with replacement. In a random forest, different trees receive different bootstrap samples, helping the ensemble learn varied patterns instead of repeating the same mistakes. section 6.4 section 6.4.1
A random forest combines bootstrap sampling with feature randomness:
- Train each decision tree on a bootstrap sample of the training observations. section 6.4.1
- Consider a random subset of features at each tree split. section 6.4
- Combine tree predictions by majority vote for classification or averaging for regression. section 6.4
Training a classifier
Configure a scikit-learn RandomForestClassifier, then call fit(X_train, y_train). The fitting process builds trees from different bootstrap samples and feature subsets, producing an ensemble ready for predictions on unseen data. section 6.4.1
>>> from sklearn.ensemble import RandomForestClassifier >>> rf = RandomForestClassifier(n_estimators = 50, >>> criterion = 'gini', >>> max_depth = 3, >>> random_state = 0)
Use the classifier configuration listing to inspect tree count, split criterion, maximum depth, and reproducibility settings before fitting. section 6.4.1
>>> rf.fit(X_train, y_train)
Use the fitting listing to connect the configured classifier with training features and target labels. section 6.4.1




