.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_packages_scikit-learn_auto_examples_plot_measuring_performance.py: Measuring Decision Tree performance ==================================== Demonstrates overfit when testing on train set. Get the data .. code-block:: python from sklearn.datasets import load_boston data = load_boston() Train and test a model .. code-block:: python from sklearn.tree import DecisionTreeRegressor clf = DecisionTreeRegressor().fit(data.data, data.target) predicted = clf.predict(data.data) expected = data.target Plot predicted as a function of expected .. code-block:: python from matplotlib import pyplot as plt plt.figure(figsize=(4, 3)) plt.scatter(expected, predicted) plt.plot([0, 50], [0, 50], '--k') plt.axis('tight') plt.xlabel('True price ($1000s)') plt.ylabel('Predicted price ($1000s)') plt.tight_layout() .. image:: /packages/scikit-learn/auto_examples/images/sphx_glr_plot_measuring_performance_001.png :class: sphx-glr-single-img Pretty much no errors! This is too good to be true: we are testing the model on the train data, which is not a mesure of generalization. **The results are not valid** **Total running time of the script:** ( 0 minutes 0.062 seconds) .. _sphx_glr_download_packages_scikit-learn_auto_examples_plot_measuring_performance.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_measuring_performance.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_measuring_performance.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_