.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_lasso_cv.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_auto_examples_plot_lasso_cv.py: ======================================================== Run LassoCV for cross-validation on the Leukemia dataset ======================================================== The example runs the LassoCV scikit-learn like estimator using the Celer algorithm. .. GENERATED FROM PYTHON SOURCE LINES 9-35 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import fetch_openml from sklearn.model_selection import KFold from celer import LassoCV from celer.plot_utils import configure_plt print(__doc__) configure_plt() print("Loading data...") dataset = fetch_openml("leukemia") X = np.asfortranarray(dataset.data.astype(float)) y = 2 * ((dataset.target == "AML") - 0.5) y -= np.mean(y) y /= np.std(y) kf = KFold(shuffle=True, n_splits=3, random_state=0) model = LassoCV(cv=kf, n_jobs=3) model.fit(X, y) print("Estimated regularization parameter alpha: %s" % model.alpha_) .. rst-class:: sphx-glr-script-out .. code-block:: none usetex mode requires TeX. Loading data... /home/circleci/.local/lib/python3.8/site-packages/sklearn/datasets/_openml.py:311: UserWarning: Multiple active versions of the dataset matching the name leukemia exist. Versions may be fundamentally different, returning version 1. warn( /home/circleci/.local/lib/python3.8/site-packages/sklearn/datasets/_openml.py:1022: FutureWarning: The default value of `parser` will change from `'liac-arff'` to `'auto'` in 1.4. You can set `parser='auto'` to silence this warning. Therefore, an `ImportError` will be raised from 1.4 if the dataset is dense and pandas is not installed. Note that the pandas parser may return different data types. See the Notes Section in fetch_openml's API doc for details. warn( Estimated regularization parameter alpha: 160.15306704065625 .. GENERATED FROM PYTHON SOURCE LINES 36-37 Display results .. GENERATED FROM PYTHON SOURCE LINES 37-50 .. code-block:: Python plt.figure(figsize=(5, 3), constrained_layout=True) plt.semilogx(model.alphas_, model.mse_path_, ':') plt.semilogx(model.alphas_, model.mse_path_.mean(axis=-1), 'k', label='Average across the folds', linewidth=2) plt.axvline(model.alpha_, linestyle='--', color='k', label='alpha: CV estimate') plt.legend() plt.xlabel(r'$\alpha$') plt.ylabel('Mean square prediction error') plt.show(block=False) .. image-sg:: /auto_examples/images/sphx_glr_plot_lasso_cv_001.png :alt: plot lasso cv :srcset: /auto_examples/images/sphx_glr_plot_lasso_cv_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 7.484 seconds) .. _sphx_glr_download_auto_examples_plot_lasso_cv.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_lasso_cv.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_lasso_cv.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_lasso_cv.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_