July 2017
Intermediate to advanced
382 pages
9h 13m
English
Similarly, we can use the BaggingRegressor class to form an ensemble of regressors.
For example, we could build an ensemble of decision trees to predict the housing prices from the Boston dataset of Chapter 3, First Steps in Supervised Learning. The syntax is almost identical to setting up a bagging classifier:
In [7]: from sklearn.ensemble import BaggingRegressor... from sklearn.tree import DecisionTreeRegressor... bag_tree = BaggingRegressor(DecisionTreeRegressor(),... max_features=0.5, n_estimators=10, ... random_state=3)
Of course, we need to load and split the dataset like we did for the breast cancer dataset:
In [8]: from sklearn.datasets import load_boston... dataset = load_boston()... X = dataset.data ...
Read now
Unlock full access