liveBook · Manning

Bootstrap sampling

As explained in Statistics Every Programmer Needs

A bootstrap sample is a sample formed by repeatedly selecting observations with replacement from an original sample.

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

How Statistics Every Programmer Needs covers it

How deep it goes
Explains sampling with replacement and its ensemble effect, but does not derive bootstrap probabilities or confidence intervals.
Examples
Demonstrates RandomForestClassifier fitting with X_train and y_train.
What it assumes
Assumes feature data and target labels, while defining resampling with replacement and its purpose from the training context.
What you can do after
Apply it via scikit-learn's RandomForestClassifier to train trees on varied resampled datasets.
How it connects
Connects bootstrap sampling to random forests, decision trees, feature subsets, overfitting, and ensemble prediction.

Also explained in

Compare how 5 books explain bootstrap sampling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.