umap-learn


Nameumap-learn JSON
Version 0.5.5 PyPI version JSON
download
home_pagehttp://github.com/lmcinnes/umap
SummaryUniform Manifold Approximation and Projection
upload_time2023-11-18 03:11:17
maintainerLeland McInnes
docs_urlNone
author
requires_python
licenseBSD
keywords dimension reduction t-sne manifold
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. -*- mode: rst -*-

.. image:: doc/logo_large.png
  :width: 600
  :alt: UMAP logo
  :align: center

|pypi_version|_ |pypi_downloads|_

|conda_version|_ |conda_downloads|_

|License|_ |build_status|_ |Coverage|_

|Docs|_ |joss_paper|_

.. |pypi_version| image:: https://img.shields.io/pypi/v/umap-learn.svg
.. _pypi_version: https://pypi.python.org/pypi/umap-learn/

.. |pypi_downloads| image:: https://pepy.tech/badge/umap-learn/month
.. _pypi_downloads: https://pepy.tech/project/umap-learn

.. |conda_version| image:: https://anaconda.org/conda-forge/umap-learn/badges/version.svg
.. _conda_version: https://anaconda.org/conda-forge/umap-learn

.. |conda_downloads| image:: https://anaconda.org/conda-forge/umap-learn/badges/downloads.svg
.. _conda_downloads: https://anaconda.org/conda-forge/umap-learn

.. |License| image:: https://img.shields.io/pypi/l/umap-learn.svg
.. _License: https://github.com/lmcinnes/umap/blob/master/LICENSE.txt

.. |build_status| image:: https://dev.azure.com/TutteInstitute/build-pipelines/_apis/build/status/lmcinnes.umap?branchName=master
.. _build_status: https://dev.azure.com/TutteInstitute/build-pipelines/_build/latest?definitionId=2&branchName=master

.. |Coverage| image:: https://coveralls.io/repos/github/lmcinnes/umap/badge.svg
.. _Coverage: https://coveralls.io/github/lmcinnes/umap

.. |Docs| image:: https://readthedocs.org/projects/umap-learn/badge/?version=latest
.. _Docs: https://umap-learn.readthedocs.io/en/latest/?badge=latest

.. |joss_paper| image:: http://joss.theoj.org/papers/10.21105/joss.00861/status.svg
.. _joss_paper: https://doi.org/10.21105/joss.00861

====
UMAP
====

Uniform Manifold Approximation and Projection (UMAP) is a dimension reduction
technique that can be used for visualisation similarly to t-SNE, but also for
general non-linear dimension reduction. The algorithm is founded on three
assumptions about the data:

1. The data is uniformly distributed on a Riemannian manifold;
2. The Riemannian metric is locally constant (or can be approximated as such);
3. The manifold is locally connected.

From these assumptions it is possible to model the manifold with a fuzzy
topological structure. The embedding is found by searching for a low dimensional
projection of the data that has the closest possible equivalent fuzzy
topological structure.

The details for the underlying mathematics can be found in
`our paper on ArXiv <https://arxiv.org/abs/1802.03426>`_:

McInnes, L, Healy, J, *UMAP: Uniform Manifold Approximation and Projection
for Dimension Reduction*, ArXiv e-prints 1802.03426, 2018

The important thing is that you don't need to worry about that—you can use
UMAP right now for dimension reduction and visualisation as easily as a drop
in replacement for scikit-learn's t-SNE.

Documentation is `available via Read the Docs <https://umap-learn.readthedocs.io/>`_.

**New: this package now also provides support for densMAP.** The densMAP algorithm augments UMAP
to preserve local density information in addition to the topological structure of the data.
Details of this method are described in the following `paper <https://doi.org/10.1038/s41587-020-00801-7>`_:

Narayan, A, Berger, B, Cho, H, *Assessing Single-Cell Transcriptomic Variability
through Density-Preserving Data Visualization*, Nature Biotechnology, 2021

----------
Installing
----------

UMAP depends upon ``scikit-learn``, and thus ``scikit-learn``'s dependencies
such as ``numpy`` and ``scipy``. UMAP adds a requirement for ``numba`` for
performance reasons. The original version used Cython, but the improved code
clarity, simplicity and performance of Numba made the transition necessary.

Requirements:

* Python 3.6 or greater
* numpy
* scipy
* scikit-learn
* numba
* tqdm
* `pynndescent <https://github.com/lmcinnes/pynndescent>`_

Recommended packages:

* For plotting
   * matplotlib
   * datashader
   * holoviews
* for Parametric UMAP
   * tensorflow > 2.0.0

**Install Options**

Conda install, via the excellent work of the conda-forge team:

.. code:: bash

    conda install -c conda-forge umap-learn

The conda-forge packages are available for Linux, OS X, and Windows 64 bit.

PyPI install, presuming you have numba and sklearn and all its requirements
(numpy and scipy) installed:

.. code:: bash

    pip install umap-learn

If you wish to use the plotting functionality you can use

.. code:: bash

    pip install umap-learn[plot]

to install all the plotting dependencies.

If you wish to use Parametric UMAP, you need to install Tensorflow, which can be
installed either using the instructions at https://www.tensorflow.org/install
(reccomended) or using

.. code:: bash

    pip install umap-learn[parametric_umap]

for a CPU-only version of Tensorflow.

If you're on an x86 processor, you can also optionally install `tbb`, which will
provide additional CPU optimizations:

.. code:: bash

    pip install umap-learn[tbb]

If pip is having difficulties pulling the dependencies then we'd suggest installing
the dependencies manually using anaconda followed by pulling umap from pip:

.. code:: bash

    conda install numpy scipy
    conda install scikit-learn
    conda install numba
    pip install umap-learn

For a manual install get this package:

.. code:: bash

    wget https://github.com/lmcinnes/umap/archive/master.zip
    unzip master.zip
    rm master.zip
    cd umap-master

Optionally, install the requirements through Conda:

.. code:: bash

    conda install scikit-learn numba

Then install the package

.. code:: bash

    python -m pip install -e .

---------------
How to use UMAP
---------------

The umap package inherits from sklearn classes, and thus drops in neatly
next to other sklearn transformers with an identical calling API.

.. code:: python

    import umap
    from sklearn.datasets import load_digits

    digits = load_digits()

    embedding = umap.UMAP().fit_transform(digits.data)

There are a number of parameters that can be set for the UMAP class; the
major ones are as follows:

 -  ``n_neighbors``: This determines the number of neighboring points used in
    local approximations of manifold structure. Larger values will result in
    more global structure being preserved at the loss of detailed local
    structure. In general this parameter should often be in the range 5 to
    50, with a choice of 10 to 15 being a sensible default.

 -  ``min_dist``: This controls how tightly the embedding is allowed compress
    points together. Larger values ensure embedded points are more evenly
    distributed, while smaller values allow the algorithm to optimise more
    accurately with regard to local structure. Sensible values are in the
    range 0.001 to 0.5, with 0.1 being a reasonable default.

 -  ``metric``: This determines the choice of metric used to measure distance
    in the input space. A wide variety of metrics are already coded, and a user
    defined function can be passed as long as it has been JITd by numba.

An example of making use of these options:

.. code:: python

    import umap
    from sklearn.datasets import load_digits

    digits = load_digits()

    embedding = umap.UMAP(n_neighbors=5,
                          min_dist=0.3,
                          metric='correlation').fit_transform(digits.data)

UMAP also supports fitting to sparse matrix data. For more details
please see `the UMAP documentation <https://umap-learn.readthedocs.io/>`_

----------------
Benefits of UMAP
----------------

UMAP has a few signficant wins in its current incarnation.

First of all UMAP is *fast*. It can handle large datasets and high
dimensional data without too much difficulty, scaling beyond what most t-SNE
packages can manage. This includes very high dimensional sparse datasets. UMAP
has successfully been used directly on data with over a million dimensions.

Second, UMAP scales well in embedding dimension—it isn't just for
visualisation! You can use UMAP as a general purpose dimension reduction
technique as a preliminary step to other machine learning tasks. With a
little care it partners well with the `hdbscan
<https://github.com/scikit-learn-contrib/hdbscan>`_ clustering library (for
more details please see `Using UMAP for Clustering
<https://umap-learn.readthedocs.io/en/latest/clustering.html>`_).

Third, UMAP often performs better at preserving some aspects of global structure
of the data than most implementations of t-SNE. This means that it can often
provide a better "big picture" view of your data as well as preserving local neighbor
relations.

Fourth, UMAP supports a wide variety of distance functions, including
non-metric distance functions such as *cosine distance* and *correlation
distance*. You can finally embed word vectors properly using cosine distance!

Fifth, UMAP supports adding new points to an existing embedding via
the standard sklearn ``transform`` method. This means that UMAP can be
used as a preprocessing transformer in sklearn pipelines.

Sixth, UMAP supports supervised and semi-supervised dimension reduction.
This means that if you have label information that you wish to use as
extra information for dimension reduction (even if it is just partial
labelling) you can do that—as simply as providing it as the ``y``
parameter in the fit method.

Seventh, UMAP supports a variety of additional experimental features including: an
"inverse transform" that can approximate a high dimensional sample that would map to
a given position in the embedding space; the ability to embed into non-euclidean
spaces including hyperbolic embeddings, and embeddings with uncertainty; very
preliminary support for embedding dataframes also exists.

Finally, UMAP has solid theoretical foundations in manifold learning
(see `our paper on ArXiv <https://arxiv.org/abs/1802.03426>`_).
This both justifies the approach and allows for further
extensions that will soon be added to the library.

------------------------
Performance and Examples
------------------------

UMAP is very efficient at embedding large high dimensional datasets. In
particular it scales well with both input dimension and embedding dimension.
For the best possible performance we recommend installing the nearest neighbor
computation library `pynndescent <https://github.com/lmcinnes/pynndescent>`_ .
UMAP will work without it, but if installed it will run faster, particularly on
multicore machines.

For a problem such as the 784-dimensional MNIST digits dataset with
70000 data samples, UMAP can complete the embedding in under a minute (as
compared with around 45 minutes for scikit-learn's t-SNE implementation).
Despite this runtime efficiency, UMAP still produces high quality embeddings.

The obligatory MNIST digits dataset, embedded in 42
seconds (with pynndescent installed and after numba jit warmup)
using a 3.1 GHz Intel Core i7 processor (n_neighbors=10, min_dist=0.001):

.. image:: images/umap_example_mnist1.png
    :alt: UMAP embedding of MNIST digits

The MNIST digits dataset is fairly straightforward, however. A better test is
the more recent "Fashion MNIST" dataset of images of fashion items (again
70000 data sample in 784 dimensions). UMAP
produced this embedding in 49 seconds (n_neighbors=5, min_dist=0.1):

.. image:: images/umap_example_fashion_mnist1.png
    :alt: UMAP embedding of "Fashion MNIST"

The UCI shuttle dataset (43500 sample in 8 dimensions) embeds well under
*correlation* distance in 44 seconds (note the longer time
required for correlation distance computations):

.. image:: images/umap_example_shuttle.png
    :alt: UMAP embedding the UCI Shuttle dataset

The following is a densMAP visualization of the MNIST digits dataset with 784 features
based on the same parameters as above (n_neighbors=10, min_dist=0.001). densMAP reveals
that the cluster corresponding to digit 1 is noticeably denser, suggesting that
there are fewer degrees of freedom in the images of 1 compared to other digits.

.. image:: images/densmap_example_mnist.png
    :alt: densMAP embedding of the MNIST dataset

--------
Plotting
--------

UMAP includes a subpackage ``umap.plot`` for plotting the results of UMAP embeddings.
This package needs to be imported separately since it has extra requirements
(matplotlib, datashader and holoviews). It allows for fast and simple plotting and
attempts to make sensible decisions to avoid overplotting and other pitfalls. An
example of use:

.. code:: python

    import umap
    import umap.plot
    from sklearn.datasets import load_digits

    digits = load_digits()

    mapper = umap.UMAP().fit(digits.data)
    umap.plot.points(mapper, labels=digits.target)

The plotting package offers basic plots, as well as interactive plots with hover
tools and various diagnostic plotting options. See the documentation for more details.

---------------
Parametric UMAP
---------------

Parametric UMAP provides support for training a neural network to learn a UMAP based
transformation of data. This can be used to support faster inference of new unseen
data, more robust inverse transforms, autoencoder versions of UMAP and
semi-supervised classification (particularly for data well separated by UMAP and very
limited amounts of labelled data). See the
`documentation of Parametric UMAP <https://umap-learn.readthedocs.io/en/0.5dev/parametric_umap.html>`_
or the
`example notebooks <https://github.com/lmcinnes/umap/tree/master/notebooks/Parametric_UMAP>`_
for more.


-------
densMAP
-------

The densMAP algorithm augments UMAP to additionally preserve local density information
in addition to the topological structure captured by UMAP. One can easily run densMAP
using the umap package by setting the ``densmap`` input flag:

.. code:: python

    embedding = umap.UMAP(densmap=True).fit_transform(data)

This functionality is built upon the densMAP `implementation <https://github.com/hhcho/densvis>`_ provided by the developers
of densMAP, who also contributed to integrating densMAP into the umap package.

densMAP inherits all of the parameters of UMAP. The following is a list of additional
parameters that can be set for densMAP:

 - ``dens_frac``: This determines the fraction of epochs (a value between 0 and 1) that will include the density-preservation term in the optimization objective. This parameter is set to 0.3 by default. Note that densMAP switches density optimization on after an initial phase of optimizing the embedding using UMAP.

 - ``dens_lambda``: This determines the weight of the density-preservation objective. Higher values prioritize density preservation, and lower values (closer to zero) prioritize the UMAP objective. Setting this parameter to zero reduces the algorithm to UMAP. Default value is 2.0.

 - ``dens_var_shift``: Regularization term added to the variance of local densities in the embedding for numerical stability. We recommend setting this parameter to 0.1, which consistently works well in many settings.

 - ``output_dens``: When this flag is True, the call to ``fit_transform`` returns, in addition to the embedding, the local radii (inverse measure of local density defined in the `densMAP paper <https://doi.org/10.1101/2020.05.12.077776>`_) for the original dataset and for the embedding. The output is a tuple ``(embedding, radii_original, radii_embedding)``. Note that the radii are log-transformed. If False, only the embedding is returned. This flag can also be used with UMAP to explore the local densities of UMAP embeddings. By default this flag is False.

For densMAP we recommend larger values of ``n_neighbors`` (e.g. 30) for reliable estimation of local density.

An example of making use of these options (based on a subsample of the mnist_784 dataset):

.. code:: python

    import umap
    from sklearn.datasets import fetch_openml
    from sklearn.utils import resample

    digits = fetch_openml(name='mnist_784')
    subsample, subsample_labels = resample(digits.data, digits.target, n_samples=7000,
                                           stratify=digits.target, random_state=1)

    embedding, r_orig, r_emb = umap.UMAP(densmap=True, dens_lambda=2.0, n_neighbors=30,
                                         output_dens=True).fit_transform(subsample)

See `the documentation <https://umap-learn.readthedocs.io/en/0.5dev/densmap_demo.html>`_ for more details.

----------------
Help and Support
----------------

Documentation is at `Read the Docs <https://umap-learn.readthedocs.io/>`_.
The documentation `includes a FAQ <https://umap-learn.readthedocs.io/en/latest/faq.html>`_ that
may answer your questions. If you still have questions then please
`open an issue <https://github.com/lmcinnes/umap/issues/new>`_
and I will try to provide any help and guidance that I can.

--------
Citation
--------

If you make use of this software for your work we would appreciate it if you
would cite the paper from the Journal of Open Source Software:

.. code:: bibtex

    @article{mcinnes2018umap-software,
      title={UMAP: Uniform Manifold Approximation and Projection},
      author={McInnes, Leland and Healy, John and Saul, Nathaniel and Grossberger, Lukas},
      journal={The Journal of Open Source Software},
      volume={3},
      number={29},
      pages={861},
      year={2018}
    }

If you would like to cite this algorithm in your work the ArXiv paper is the
current reference:

.. code:: bibtex

   @article{2018arXivUMAP,
        author = {{McInnes}, L. and {Healy}, J. and {Melville}, J.},
        title = "{UMAP: Uniform Manifold Approximation
        and Projection for Dimension Reduction}",
        journal = {ArXiv e-prints},
        archivePrefix = "arXiv",
        eprint = {1802.03426},
        primaryClass = "stat.ML",
        keywords = {Statistics - Machine Learning,
                    Computer Science - Computational Geometry,
                    Computer Science - Learning},
        year = 2018,
        month = feb,
   }

Additionally, if you use the densMAP algorithm in your work please cite the following reference:

.. code:: bibtex

    @article {NBC2020,
        author = {Narayan, Ashwin and Berger, Bonnie and Cho, Hyunghoon},
        title = {Assessing Single-Cell Transcriptomic Variability through Density-Preserving Data Visualization},
        journal = {Nature Biotechnology},
        year = {2021},
        doi = {10.1038/s41587-020-00801-7},
        publisher = {Springer Nature},
        URL = {https://doi.org/10.1038/s41587-020-00801-7},
        eprint = {https://www.biorxiv.org/content/early/2020/05/14/2020.05.12.077776.full.pdf},
    }

If you use the Parametric UMAP algorithm in your work please cite the following reference:

.. code:: bibtex

    @article {SMG2020,
        author = {Sainburg, Tim and McInnes, Leland and Gentner, Timothy Q.},
        title = {Parametric UMAP: learning embeddings with deep neural networks for representation and semi-supervised learning},
        journal = {ArXiv e-prints},
        archivePrefix = "arXiv",
        eprint = {2009.12981},
        primaryClass = "stat.ML",
        keywords = {Statistics - Machine Learning,
                    Computer Science - Computational Geometry,
                    Computer Science - Learning},
        year = 2020,
        }


-------
License
-------

The umap package is 3-clause BSD licensed.

We would like to note that the umap package makes heavy use of
NumFOCUS sponsored projects, and would not be possible without
their support of those projects, so please `consider contributing to NumFOCUS <https://www.numfocus.org/membership>`_.

------------
Contributing
------------

Contributions are more than welcome! There are lots of opportunities
for potential projects, so please get in touch if you would like to
help out. Everything from code to notebooks to
examples and documentation are all *equally valuable* so please don't feel
you can't contribute. To contribute please
`fork the project <https://github.com/lmcinnes/umap/issues#fork-destination-box>`_
make your changes and
submit a pull request. We will do our best to work through any issues with
you and get your code merged into the main branch.



            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/lmcinnes/umap",
    "name": "umap-learn",
    "maintainer": "Leland McInnes",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "leland.mcinnes@gmail.com",
    "keywords": "dimension reduction t-sne manifold",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/4f/3c/a81281db93878bcd80da672a9b520674f930e0a18d73a2e4b23e8b176cb6/umap-learn-0.5.5.tar.gz",
    "platform": null,
    "description": ".. -*- mode: rst -*-\n\n.. image:: doc/logo_large.png\n  :width: 600\n  :alt: UMAP logo\n  :align: center\n\n|pypi_version|_ |pypi_downloads|_\n\n|conda_version|_ |conda_downloads|_\n\n|License|_ |build_status|_ |Coverage|_\n\n|Docs|_ |joss_paper|_\n\n.. |pypi_version| image:: https://img.shields.io/pypi/v/umap-learn.svg\n.. _pypi_version: https://pypi.python.org/pypi/umap-learn/\n\n.. |pypi_downloads| image:: https://pepy.tech/badge/umap-learn/month\n.. _pypi_downloads: https://pepy.tech/project/umap-learn\n\n.. |conda_version| image:: https://anaconda.org/conda-forge/umap-learn/badges/version.svg\n.. _conda_version: https://anaconda.org/conda-forge/umap-learn\n\n.. |conda_downloads| image:: https://anaconda.org/conda-forge/umap-learn/badges/downloads.svg\n.. _conda_downloads: https://anaconda.org/conda-forge/umap-learn\n\n.. |License| image:: https://img.shields.io/pypi/l/umap-learn.svg\n.. _License: https://github.com/lmcinnes/umap/blob/master/LICENSE.txt\n\n.. |build_status| image:: https://dev.azure.com/TutteInstitute/build-pipelines/_apis/build/status/lmcinnes.umap?branchName=master\n.. _build_status: https://dev.azure.com/TutteInstitute/build-pipelines/_build/latest?definitionId=2&branchName=master\n\n.. |Coverage| image:: https://coveralls.io/repos/github/lmcinnes/umap/badge.svg\n.. _Coverage: https://coveralls.io/github/lmcinnes/umap\n\n.. |Docs| image:: https://readthedocs.org/projects/umap-learn/badge/?version=latest\n.. _Docs: https://umap-learn.readthedocs.io/en/latest/?badge=latest\n\n.. |joss_paper| image:: http://joss.theoj.org/papers/10.21105/joss.00861/status.svg\n.. _joss_paper: https://doi.org/10.21105/joss.00861\n\n====\nUMAP\n====\n\nUniform Manifold Approximation and Projection (UMAP) is a dimension reduction\ntechnique that can be used for visualisation similarly to t-SNE, but also for\ngeneral non-linear dimension reduction. The algorithm is founded on three\nassumptions about the data:\n\n1. The data is uniformly distributed on a Riemannian manifold;\n2. The Riemannian metric is locally constant (or can be approximated as such);\n3. The manifold is locally connected.\n\nFrom these assumptions it is possible to model the manifold with a fuzzy\ntopological structure. The embedding is found by searching for a low dimensional\nprojection of the data that has the closest possible equivalent fuzzy\ntopological structure.\n\nThe details for the underlying mathematics can be found in\n`our paper on ArXiv <https://arxiv.org/abs/1802.03426>`_:\n\nMcInnes, L, Healy, J, *UMAP: Uniform Manifold Approximation and Projection\nfor Dimension Reduction*, ArXiv e-prints 1802.03426, 2018\n\nThe important thing is that you don't need to worry about that\u2014you can use\nUMAP right now for dimension reduction and visualisation as easily as a drop\nin replacement for scikit-learn's t-SNE.\n\nDocumentation is `available via Read the Docs <https://umap-learn.readthedocs.io/>`_.\n\n**New: this package now also provides support for densMAP.** The densMAP algorithm augments UMAP\nto preserve local density information in addition to the topological structure of the data.\nDetails of this method are described in the following `paper <https://doi.org/10.1038/s41587-020-00801-7>`_:\n\nNarayan, A, Berger, B, Cho, H, *Assessing Single-Cell Transcriptomic Variability\nthrough Density-Preserving Data Visualization*, Nature Biotechnology, 2021\n\n----------\nInstalling\n----------\n\nUMAP depends upon ``scikit-learn``, and thus ``scikit-learn``'s dependencies\nsuch as ``numpy`` and ``scipy``. UMAP adds a requirement for ``numba`` for\nperformance reasons. The original version used Cython, but the improved code\nclarity, simplicity and performance of Numba made the transition necessary.\n\nRequirements:\n\n* Python 3.6 or greater\n* numpy\n* scipy\n* scikit-learn\n* numba\n* tqdm\n* `pynndescent <https://github.com/lmcinnes/pynndescent>`_\n\nRecommended packages:\n\n* For plotting\n   * matplotlib\n   * datashader\n   * holoviews\n* for Parametric UMAP\n   * tensorflow > 2.0.0\n\n**Install Options**\n\nConda install, via the excellent work of the conda-forge team:\n\n.. code:: bash\n\n    conda install -c conda-forge umap-learn\n\nThe conda-forge packages are available for Linux, OS X, and Windows 64 bit.\n\nPyPI install, presuming you have numba and sklearn and all its requirements\n(numpy and scipy) installed:\n\n.. code:: bash\n\n    pip install umap-learn\n\nIf you wish to use the plotting functionality you can use\n\n.. code:: bash\n\n    pip install umap-learn[plot]\n\nto install all the plotting dependencies.\n\nIf you wish to use Parametric UMAP, you need to install Tensorflow, which can be\ninstalled either using the instructions at https://www.tensorflow.org/install\n(reccomended) or using\n\n.. code:: bash\n\n    pip install umap-learn[parametric_umap]\n\nfor a CPU-only version of Tensorflow.\n\nIf you're on an x86 processor, you can also optionally install `tbb`, which will\nprovide additional CPU optimizations:\n\n.. code:: bash\n\n    pip install umap-learn[tbb]\n\nIf pip is having difficulties pulling the dependencies then we'd suggest installing\nthe dependencies manually using anaconda followed by pulling umap from pip:\n\n.. code:: bash\n\n    conda install numpy scipy\n    conda install scikit-learn\n    conda install numba\n    pip install umap-learn\n\nFor a manual install get this package:\n\n.. code:: bash\n\n    wget https://github.com/lmcinnes/umap/archive/master.zip\n    unzip master.zip\n    rm master.zip\n    cd umap-master\n\nOptionally, install the requirements through Conda:\n\n.. code:: bash\n\n    conda install scikit-learn numba\n\nThen install the package\n\n.. code:: bash\n\n    python -m pip install -e .\n\n---------------\nHow to use UMAP\n---------------\n\nThe umap package inherits from sklearn classes, and thus drops in neatly\nnext to other sklearn transformers with an identical calling API.\n\n.. code:: python\n\n    import umap\n    from sklearn.datasets import load_digits\n\n    digits = load_digits()\n\n    embedding = umap.UMAP().fit_transform(digits.data)\n\nThere are a number of parameters that can be set for the UMAP class; the\nmajor ones are as follows:\n\n -  ``n_neighbors``: This determines the number of neighboring points used in\n    local approximations of manifold structure. Larger values will result in\n    more global structure being preserved at the loss of detailed local\n    structure. In general this parameter should often be in the range 5 to\n    50, with a choice of 10 to 15 being a sensible default.\n\n -  ``min_dist``: This controls how tightly the embedding is allowed compress\n    points together. Larger values ensure embedded points are more evenly\n    distributed, while smaller values allow the algorithm to optimise more\n    accurately with regard to local structure. Sensible values are in the\n    range 0.001 to 0.5, with 0.1 being a reasonable default.\n\n -  ``metric``: This determines the choice of metric used to measure distance\n    in the input space. A wide variety of metrics are already coded, and a user\n    defined function can be passed as long as it has been JITd by numba.\n\nAn example of making use of these options:\n\n.. code:: python\n\n    import umap\n    from sklearn.datasets import load_digits\n\n    digits = load_digits()\n\n    embedding = umap.UMAP(n_neighbors=5,\n                          min_dist=0.3,\n                          metric='correlation').fit_transform(digits.data)\n\nUMAP also supports fitting to sparse matrix data. For more details\nplease see `the UMAP documentation <https://umap-learn.readthedocs.io/>`_\n\n----------------\nBenefits of UMAP\n----------------\n\nUMAP has a few signficant wins in its current incarnation.\n\nFirst of all UMAP is *fast*. It can handle large datasets and high\ndimensional data without too much difficulty, scaling beyond what most t-SNE\npackages can manage. This includes very high dimensional sparse datasets. UMAP\nhas successfully been used directly on data with over a million dimensions.\n\nSecond, UMAP scales well in embedding dimension\u2014it isn't just for\nvisualisation! You can use UMAP as a general purpose dimension reduction\ntechnique as a preliminary step to other machine learning tasks. With a\nlittle care it partners well with the `hdbscan\n<https://github.com/scikit-learn-contrib/hdbscan>`_ clustering library (for\nmore details please see `Using UMAP for Clustering\n<https://umap-learn.readthedocs.io/en/latest/clustering.html>`_).\n\nThird, UMAP often performs better at preserving some aspects of global structure\nof the data than most implementations of t-SNE. This means that it can often\nprovide a better \"big picture\" view of your data as well as preserving local neighbor\nrelations.\n\nFourth, UMAP supports a wide variety of distance functions, including\nnon-metric distance functions such as *cosine distance* and *correlation\ndistance*. You can finally embed word vectors properly using cosine distance!\n\nFifth, UMAP supports adding new points to an existing embedding via\nthe standard sklearn ``transform`` method. This means that UMAP can be\nused as a preprocessing transformer in sklearn pipelines.\n\nSixth, UMAP supports supervised and semi-supervised dimension reduction.\nThis means that if you have label information that you wish to use as\nextra information for dimension reduction (even if it is just partial\nlabelling) you can do that\u2014as simply as providing it as the ``y``\nparameter in the fit method.\n\nSeventh, UMAP supports a variety of additional experimental features including: an\n\"inverse transform\" that can approximate a high dimensional sample that would map to\na given position in the embedding space; the ability to embed into non-euclidean\nspaces including hyperbolic embeddings, and embeddings with uncertainty; very\npreliminary support for embedding dataframes also exists.\n\nFinally, UMAP has solid theoretical foundations in manifold learning\n(see `our paper on ArXiv <https://arxiv.org/abs/1802.03426>`_).\nThis both justifies the approach and allows for further\nextensions that will soon be added to the library.\n\n------------------------\nPerformance and Examples\n------------------------\n\nUMAP is very efficient at embedding large high dimensional datasets. In\nparticular it scales well with both input dimension and embedding dimension.\nFor the best possible performance we recommend installing the nearest neighbor\ncomputation library `pynndescent <https://github.com/lmcinnes/pynndescent>`_ .\nUMAP will work without it, but if installed it will run faster, particularly on\nmulticore machines.\n\nFor a problem such as the 784-dimensional MNIST digits dataset with\n70000 data samples, UMAP can complete the embedding in under a minute (as\ncompared with around 45 minutes for scikit-learn's t-SNE implementation).\nDespite this runtime efficiency, UMAP still produces high quality embeddings.\n\nThe obligatory MNIST digits dataset, embedded in 42\nseconds (with pynndescent installed and after numba jit warmup)\nusing a 3.1 GHz Intel Core i7 processor (n_neighbors=10, min_dist=0.001):\n\n.. image:: images/umap_example_mnist1.png\n    :alt: UMAP embedding of MNIST digits\n\nThe MNIST digits dataset is fairly straightforward, however. A better test is\nthe more recent \"Fashion MNIST\" dataset of images of fashion items (again\n70000 data sample in 784 dimensions). UMAP\nproduced this embedding in 49 seconds (n_neighbors=5, min_dist=0.1):\n\n.. image:: images/umap_example_fashion_mnist1.png\n    :alt: UMAP embedding of \"Fashion MNIST\"\n\nThe UCI shuttle dataset (43500 sample in 8 dimensions) embeds well under\n*correlation* distance in 44 seconds (note the longer time\nrequired for correlation distance computations):\n\n.. image:: images/umap_example_shuttle.png\n    :alt: UMAP embedding the UCI Shuttle dataset\n\nThe following is a densMAP visualization of the MNIST digits dataset with 784 features\nbased on the same parameters as above (n_neighbors=10, min_dist=0.001). densMAP reveals\nthat the cluster corresponding to digit 1 is noticeably denser, suggesting that\nthere are fewer degrees of freedom in the images of 1 compared to other digits.\n\n.. image:: images/densmap_example_mnist.png\n    :alt: densMAP embedding of the MNIST dataset\n\n--------\nPlotting\n--------\n\nUMAP includes a subpackage ``umap.plot`` for plotting the results of UMAP embeddings.\nThis package needs to be imported separately since it has extra requirements\n(matplotlib, datashader and holoviews). It allows for fast and simple plotting and\nattempts to make sensible decisions to avoid overplotting and other pitfalls. An\nexample of use:\n\n.. code:: python\n\n    import umap\n    import umap.plot\n    from sklearn.datasets import load_digits\n\n    digits = load_digits()\n\n    mapper = umap.UMAP().fit(digits.data)\n    umap.plot.points(mapper, labels=digits.target)\n\nThe plotting package offers basic plots, as well as interactive plots with hover\ntools and various diagnostic plotting options. See the documentation for more details.\n\n---------------\nParametric UMAP\n---------------\n\nParametric UMAP provides support for training a neural network to learn a UMAP based\ntransformation of data. This can be used to support faster inference of new unseen\ndata, more robust inverse transforms, autoencoder versions of UMAP and\nsemi-supervised classification (particularly for data well separated by UMAP and very\nlimited amounts of labelled data). See the\n`documentation of Parametric UMAP <https://umap-learn.readthedocs.io/en/0.5dev/parametric_umap.html>`_\nor the\n`example notebooks <https://github.com/lmcinnes/umap/tree/master/notebooks/Parametric_UMAP>`_\nfor more.\n\n\n-------\ndensMAP\n-------\n\nThe densMAP algorithm augments UMAP to additionally preserve local density information\nin addition to the topological structure captured by UMAP. One can easily run densMAP\nusing the umap package by setting the ``densmap`` input flag:\n\n.. code:: python\n\n    embedding = umap.UMAP(densmap=True).fit_transform(data)\n\nThis functionality is built upon the densMAP `implementation <https://github.com/hhcho/densvis>`_ provided by the developers\nof densMAP, who also contributed to integrating densMAP into the umap package.\n\ndensMAP inherits all of the parameters of UMAP. The following is a list of additional\nparameters that can be set for densMAP:\n\n - ``dens_frac``: This determines the fraction of epochs (a value between 0 and 1) that will include the density-preservation term in the optimization objective. This parameter is set to 0.3 by default. Note that densMAP switches density optimization on after an initial phase of optimizing the embedding using UMAP.\n\n - ``dens_lambda``: This determines the weight of the density-preservation objective. Higher values prioritize density preservation, and lower values (closer to zero) prioritize the UMAP objective. Setting this parameter to zero reduces the algorithm to UMAP. Default value is 2.0.\n\n - ``dens_var_shift``: Regularization term added to the variance of local densities in the embedding for numerical stability. We recommend setting this parameter to 0.1, which consistently works well in many settings.\n\n - ``output_dens``: When this flag is True, the call to ``fit_transform`` returns, in addition to the embedding, the local radii (inverse measure of local density defined in the `densMAP paper <https://doi.org/10.1101/2020.05.12.077776>`_) for the original dataset and for the embedding. The output is a tuple ``(embedding, radii_original, radii_embedding)``. Note that the radii are log-transformed. If False, only the embedding is returned. This flag can also be used with UMAP to explore the local densities of UMAP embeddings. By default this flag is False.\n\nFor densMAP we recommend larger values of ``n_neighbors`` (e.g. 30) for reliable estimation of local density.\n\nAn example of making use of these options (based on a subsample of the mnist_784 dataset):\n\n.. code:: python\n\n    import umap\n    from sklearn.datasets import fetch_openml\n    from sklearn.utils import resample\n\n    digits = fetch_openml(name='mnist_784')\n    subsample, subsample_labels = resample(digits.data, digits.target, n_samples=7000,\n                                           stratify=digits.target, random_state=1)\n\n    embedding, r_orig, r_emb = umap.UMAP(densmap=True, dens_lambda=2.0, n_neighbors=30,\n                                         output_dens=True).fit_transform(subsample)\n\nSee `the documentation <https://umap-learn.readthedocs.io/en/0.5dev/densmap_demo.html>`_ for more details.\n\n----------------\nHelp and Support\n----------------\n\nDocumentation is at `Read the Docs <https://umap-learn.readthedocs.io/>`_.\nThe documentation `includes a FAQ <https://umap-learn.readthedocs.io/en/latest/faq.html>`_ that\nmay answer your questions. If you still have questions then please\n`open an issue <https://github.com/lmcinnes/umap/issues/new>`_\nand I will try to provide any help and guidance that I can.\n\n--------\nCitation\n--------\n\nIf you make use of this software for your work we would appreciate it if you\nwould cite the paper from the Journal of Open Source Software:\n\n.. code:: bibtex\n\n    @article{mcinnes2018umap-software,\n      title={UMAP: Uniform Manifold Approximation and Projection},\n      author={McInnes, Leland and Healy, John and Saul, Nathaniel and Grossberger, Lukas},\n      journal={The Journal of Open Source Software},\n      volume={3},\n      number={29},\n      pages={861},\n      year={2018}\n    }\n\nIf you would like to cite this algorithm in your work the ArXiv paper is the\ncurrent reference:\n\n.. code:: bibtex\n\n   @article{2018arXivUMAP,\n        author = {{McInnes}, L. and {Healy}, J. and {Melville}, J.},\n        title = \"{UMAP: Uniform Manifold Approximation\n        and Projection for Dimension Reduction}\",\n        journal = {ArXiv e-prints},\n        archivePrefix = \"arXiv\",\n        eprint = {1802.03426},\n        primaryClass = \"stat.ML\",\n        keywords = {Statistics - Machine Learning,\n                    Computer Science - Computational Geometry,\n                    Computer Science - Learning},\n        year = 2018,\n        month = feb,\n   }\n\nAdditionally, if you use the densMAP algorithm in your work please cite the following reference:\n\n.. code:: bibtex\n\n    @article {NBC2020,\n        author = {Narayan, Ashwin and Berger, Bonnie and Cho, Hyunghoon},\n        title = {Assessing Single-Cell Transcriptomic Variability through Density-Preserving Data Visualization},\n        journal = {Nature Biotechnology},\n        year = {2021},\n        doi = {10.1038/s41587-020-00801-7},\n        publisher = {Springer Nature},\n        URL = {https://doi.org/10.1038/s41587-020-00801-7},\n        eprint = {https://www.biorxiv.org/content/early/2020/05/14/2020.05.12.077776.full.pdf},\n    }\n\nIf you use the Parametric UMAP algorithm in your work please cite the following reference:\n\n.. code:: bibtex\n\n    @article {SMG2020,\n        author = {Sainburg, Tim and McInnes, Leland and Gentner, Timothy Q.},\n        title = {Parametric UMAP: learning embeddings with deep neural networks for representation and semi-supervised learning},\n        journal = {ArXiv e-prints},\n        archivePrefix = \"arXiv\",\n        eprint = {2009.12981},\n        primaryClass = \"stat.ML\",\n        keywords = {Statistics - Machine Learning,\n                    Computer Science - Computational Geometry,\n                    Computer Science - Learning},\n        year = 2020,\n        }\n\n\n-------\nLicense\n-------\n\nThe umap package is 3-clause BSD licensed.\n\nWe would like to note that the umap package makes heavy use of\nNumFOCUS sponsored projects, and would not be possible without\ntheir support of those projects, so please `consider contributing to NumFOCUS <https://www.numfocus.org/membership>`_.\n\n------------\nContributing\n------------\n\nContributions are more than welcome! There are lots of opportunities\nfor potential projects, so please get in touch if you would like to\nhelp out. Everything from code to notebooks to\nexamples and documentation are all *equally valuable* so please don't feel\nyou can't contribute. To contribute please\n`fork the project <https://github.com/lmcinnes/umap/issues#fork-destination-box>`_\nmake your changes and\nsubmit a pull request. We will do our best to work through any issues with\nyou and get your code merged into the main branch.\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Uniform Manifold Approximation and Projection",
    "version": "0.5.5",
    "project_urls": {
        "Homepage": "http://github.com/lmcinnes/umap"
    },
    "split_keywords": [
        "dimension",
        "reduction",
        "t-sne",
        "manifold"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4f3ca81281db93878bcd80da672a9b520674f930e0a18d73a2e4b23e8b176cb6",
                "md5": "90a4f4b46c97f9b3dc3d8a5d174c110e",
                "sha256": "c54d607364413eade968b73ba07c8b3ea14412817f53cd07b6f720ac957293c4"
            },
            "downloads": -1,
            "filename": "umap-learn-0.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "90a4f4b46c97f9b3dc3d8a5d174c110e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 90882,
            "upload_time": "2023-11-18T03:11:17",
            "upload_time_iso_8601": "2023-11-18T03:11:17.438220Z",
            "url": "https://files.pythonhosted.org/packages/4f/3c/a81281db93878bcd80da672a9b520674f930e0a18d73a2e4b23e8b176cb6/umap-learn-0.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-18 03:11:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lmcinnes",
    "github_project": "umap",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "lcname": "umap-learn"
}
        
Elapsed time: 0.24493s