.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_ensemble_plot_voting_regressor.py: ================================================= Plot individual and voting regression predictions ================================================= .. currentmodule:: sklearn Plot individual and averaged regression predictions for Boston dataset. First, three exemplary regressors are initialized (:class:`~ensemble.GradientBoostingRegressor`, :class:`~ensemble.RandomForestRegressor`, and :class:`~linear_model.LinearRegression`) and used to initialize a :class:`~ensemble.VotingRegressor`. The red starred dots are the averaged predictions. .. image:: /auto_examples/ensemble/images/sphx_glr_plot_voting_regressor_001.png :class: sphx-glr-single-img .. code-block:: default print(__doc__) 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 X, y = datasets.load_boston(return_X_y=True) # 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)]) reg1.fit(X, y) reg2.fit(X, y) reg3.fit(X, y) ereg.fit(X, y) xt = X[:20] plt.figure() 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, labelbottom=False) plt.ylabel('predicted') plt.xlabel('training samples') plt.legend(loc="best") plt.title('Comparison of individual predictions with averaged') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.461 seconds) **Estimated memory usage:** 8 MB .. _sphx_glr_download_auto_examples_ensemble_plot_voting_regressor.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/0.22.X?urlpath=lab/tree/notebooks/auto_examples/ensemble/plot_voting_regressor.ipynb :width: 150 px .. container:: sphx-glr-download :download:`Download Python source code: plot_voting_regressor.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_voting_regressor.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_