.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "packages/scikit-learn/auto_examples/plot_measuring_performance.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` 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. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Get the data .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: default from sklearn.datasets import fetch_california_housing data = fetch_california_housing(as_frame=True) .. GENERATED FROM PYTHON SOURCE LINES 15-16 Train and test a model .. GENERATED FROM PYTHON SOURCE LINES 16-22 .. code-block:: default from sklearn.tree import DecisionTreeRegressor clf = DecisionTreeRegressor().fit(data.data, data.target) predicted = clf.predict(data.data) expected = data.target .. GENERATED FROM PYTHON SOURCE LINES 23-24 Plot predicted as a function of expected .. GENERATED FROM PYTHON SOURCE LINES 24-34 .. code-block:: default import matplotlib.pyplot as plt plt.figure(figsize=(4, 3)) plt.scatter(expected, predicted) plt.plot([0, 5], [0, 5], '--k') plt.axis('tight') plt.xlabel('True price ($100k)') plt.ylabel('Predicted price ($100k)') plt.tight_layout() .. image-sg:: /packages/scikit-learn/auto_examples/images/sphx_glr_plot_measuring_performance_001.png :alt: plot measuring performance :srcset: /packages/scikit-learn/auto_examples/images/sphx_glr_plot_measuring_performance_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-41 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** .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.533 seconds) .. _sphx_glr_download_packages_scikit-learn_auto_examples_plot_measuring_performance.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_measuring_performance.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_measuring_performance.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_