Plot individual and voting regression predictionsΒΆ

Plot individual and averaged regression predictions for Boston dataset.

First, three exemplary regressors are initialized (GradientBoostingRegressor, RandomForestRegressor, and LinearRegression) and used to initialize a VotingRegressor.

The red starred dots are the averaged predictions.


import matplotlib.pyplot as plt

from sklearn import datasets
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import VotingRegressor

# Loading some example data
boston = datasets.load_boston()
X =
y =

# Training classifiers
reg1 = GradientBoostingRegressor(random_state=1, n_estimators=10)
reg2 = RandomForestRegressor(random_state=1, n_estimators=10)
reg3 = LinearRegression()
ereg = VotingRegressor([('gb', reg1), ('rf', reg2), ('lr', reg3)]), y), y), y), y)

xt = X[:20]

plt.plot(reg1.predict(xt), 'gd', label='GradientBoostingRegressor')
plt.plot(reg2.predict(xt), 'b^', label='RandomForestRegressor')
plt.plot(reg3.predict(xt), 'ys', label='LinearRegression')
plt.plot(ereg.predict(xt), 'r*', label='VotingRegressor')
plt.tick_params(axis='x', which='both', bottom=False, top=False,
plt.xlabel('training samples')
plt.title('Comparison of individual predictions with averaged')

Total running time of the script: ( 0 minutes 0.114 seconds)

Gallery generated by Sphinx-Gallery