Bagging regressors are similar to bagging classifiers. They train each regressor model on a random subset of the original training set and aggregate the predictions. Then, the aggregation averages over the iterations because the target variable is numeric. In the following recipe, we are going to showcase the implementation of a bagging regressor with bootstrap samples.
Bagging regressors
Getting ready
We will import the required libraries, BaggingRegressor and DecisionTreeRegressor, from sklearn.ensemble and sklearn.tree respectively:
from sklearn.ensemble import BaggingRegressor
from sklearn.tree import DecisionTreeRegressor
We read our dataset, which is bostonhousing.csv, and look at the dimensions of the DataFrame:
df_housingdata...