.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/linear_model/plot_lasso_lars.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 or to run this example in your browser via JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_linear_model_plot_lasso_lars.py: ===================== Lasso path using LARS ===================== Computes Lasso Path along the regularization parameter using the LARS algorithm on the diabetes dataset. Each color represents a different feature of the coefficient vector, and this is displayed as a function of the regularization parameter. .. GENERATED FROM PYTHON SOURCE LINES 12-38 .. image-sg:: /auto_examples/linear_model/images/sphx_glr_plot_lasso_lars_001.png :alt: LASSO Path :srcset: /auto_examples/linear_model/images/sphx_glr_plot_lasso_lars_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Computing regularization path using the LARS ... . | .. code-block:: Python # Author: Fabian Pedregosa # Alexandre Gramfort # License: BSD 3 clause import matplotlib.pyplot as plt import numpy as np from sklearn import datasets, linear_model X, y = datasets.load_diabetes(return_X_y=True) print("Computing regularization path using the LARS ...") _, _, coefs = linear_model.lars_path(X, y, method="lasso", verbose=True) xx = np.sum(np.abs(coefs.T), axis=1) xx /= xx[-1] plt.plot(xx, coefs.T) ymin, ymax = plt.ylim() plt.vlines(xx, ymin, ymax, linestyle="dashed") plt.xlabel("|coef| / max|coef|") plt.ylabel("Coefficients") plt.title("LASSO Path") plt.axis("tight") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.112 seconds) .. _sphx_glr_download_auto_examples_linear_model_plot_lasso_lars.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/linear_model/plot_lasso_lars.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/?path=auto_examples/linear_model/plot_lasso_lars.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_lasso_lars.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_lasso_lars.py ` .. include:: plot_lasso_lars.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_