
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/manifold/plot_swissroll.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        Click :ref:`here <sphx_glr_download_auto_examples_manifold_plot_swissroll.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_manifold_plot_swissroll.py:


===================================
Swiss Roll reduction with LLE
===================================

An illustration of Swiss Roll reduction
with locally linear embedding

.. GENERATED FROM PYTHON SOURCE LINES 9-47



.. image-sg:: /auto_examples/manifold/images/sphx_glr_plot_swissroll_001.png
   :alt: Original data, Projected data
   :srcset: /auto_examples/manifold/images/sphx_glr_plot_swissroll_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    Computing LLE embedding
    Done. Reconstruction error: 7.32634e-08






|

.. code-block:: default


    # Author: Fabian Pedregosa -- <fabian.pedregosa@inria.fr>
    # License: BSD 3 clause (C) INRIA 2011

    print(__doc__)

    import matplotlib.pyplot as plt

    # This import is needed to modify the way figure behaves
    from mpl_toolkits.mplot3d import Axes3D
    Axes3D

    #----------------------------------------------------------------------
    # Locally linear embedding of the swiss roll

    from sklearn import manifold, datasets
    X, color = datasets.make_swiss_roll(n_samples=1500)

    print("Computing LLE embedding")
    X_r, err = manifold.locally_linear_embedding(X, n_neighbors=12,
                                                 n_components=2)
    print("Done. Reconstruction error: %g" % err)

    #----------------------------------------------------------------------
    # Plot result

    fig = plt.figure()

    ax = fig.add_subplot(211, projection='3d')
    ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=color, cmap=plt.cm.Spectral)

    ax.set_title("Original data")
    ax = fig.add_subplot(212)
    ax.scatter(X_r[:, 0], X_r[:, 1], c=color, cmap=plt.cm.Spectral)
    plt.axis('tight')
    plt.xticks([]), plt.yticks([])
    plt.title('Projected data')
    plt.show()


.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_auto_examples_manifold_plot_swissroll.py:


.. only :: html

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



  .. container:: sphx-glr-download sphx-glr-download-python

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



  .. container:: sphx-glr-download sphx-glr-download-jupyter

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


.. only:: html

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

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