.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_residuals.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_residuals.py: Plot Residuals ============== This example demonstrates plotting errors / residuals. Code has been adapted from the `plotly example `_ .. GENERATED FROM PYTHON SOURCE LINES 11-25 .. code-block:: default import logging import plotly from sklearn import datasets from sklearn.linear_model import Lasso from sklearn.model_selection import train_test_split from sklearn.pipeline import make_pipeline from elphick.sklearn_viz.residuals import Errors logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(module)s - %(funcName)s: %(message)s', datefmt='%Y-%m-%dT%H:%M:%S%z') .. GENERATED FROM PYTHON SOURCE LINES 26-29 Data generation and model fitting --------------------------------- We mimic a simple model fit per the sklearn example. .. GENERATED FROM PYTHON SOURCE LINES 29-43 .. code-block:: default # Load the diabetes dataset diabetes = datasets.load_diabetes(as_frame=True) X, y = diabetes.data, diabetes.target y.name = "progression" X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.1, random_state=13 ) mdl = make_pipeline(Lasso()) mdl.set_output(transform="pandas") mdl.fit(X_train, y_train) .. raw:: html
Pipeline(steps=[('lasso', Lasso())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


.. GENERATED FROM PYTHON SOURCE LINES 44-46 Demonstrate the plot -------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: default obj_res: Errors = Errors(mdl=mdl, x_test=X_test, y_test=y_test) fig = obj_res.plot() # noinspection PyTypeChecker plotly.io.show(fig) .. raw:: html :file: images/sphx_glr_plot_residuals_001.html .. GENERATED FROM PYTHON SOURCE LINES 53-54 Add marginal histograms .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: default fig = obj_res.plot(marginal=True) fig .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.266 seconds) .. _sphx_glr_download_auto_examples_plot_residuals.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_residuals.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_residuals.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_