Session Ready
Exercise

Training with bootstrapping

Let's now build a "weak" decision tree classifier and train it on a sample of the training set drawn with replacement. This will help you understand what happens on every iteration of a bagging ensemble.

To take a sample, you'll use pandas' .sample() method, which has a replace parameter. For example, the following line of code samples with replacement from the whole DataFrame df:

df.sample(frac=1.0, replace=True, random_state=42)
Instructions
100 XP
  • Take a sample drawn with replacement (replace=True) from the whole (frac=1.0) training set, X_train.
  • Build a decision tree classifier using the parameters max_depth = 4 and max_features = 2.
  • Fit the model to the sampled training data.