.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_auto_examples_linear_model_plot_logistic_path.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_linear_model_plot_logistic_path.py:


=================================
Path with L1- Logistic Regression
=================================

Computes path on IRIS dataset.




.. code-block:: python

    print(__doc__)

    # Author: Alexandre Gramfort <alexandre.gramfort@inria.fr>
    # License: BSD 3 clause

    from datetime import datetime
    import numpy as np
    import matplotlib.pyplot as plt

    from sklearn import linear_model
    from sklearn import datasets
    from sklearn.svm import l1_min_c

    iris = datasets.load_iris()
    X = iris.data
    y = iris.target

    X = X[y != 2]
    y = y[y != 2]

    X -= np.mean(X, 0)

    # #############################################################################
    # Demo path functions

    cs = l1_min_c(X, y, loss='log') * np.logspace(0, 3)


    print("Computing regularization path ...")
    start = datetime.now()
    clf = linear_model.LogisticRegression(C=1.0, penalty='l1', tol=1e-6)
    coefs_ = []
    for c in cs:
        clf.set_params(C=c)
        clf.fit(X, y)
        coefs_.append(clf.coef_.ravel().copy())
    print("This took ", datetime.now() - start)

    coefs_ = np.array(coefs_)
    plt.plot(np.log10(cs), coefs_)
    ymin, ymax = plt.ylim()
    plt.xlabel('log(C)')
    plt.ylabel('Coefficients')
    plt.title('Logistic Regression Path')
    plt.axis('tight')
    plt.show()

**Total running time of the script:** ( 0 minutes  0.000 seconds)


.. _sphx_glr_download_auto_examples_linear_model_plot_logistic_path.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: plot_logistic_path.py <plot_logistic_path.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: plot_logistic_path.ipynb <plot_logistic_path.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
