by PAIR-code

PAIR-code / umap-js

JavaScript implementation of UMAP

165 Stars 17 Forks Last release: over 1 year ago (1.2.2) Apache License 2.0 103 Commits 6 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Build Status


This is a JavaScript reimplementation of UMAP from the python implementation found at

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.

There are a few important differences between the python implementation and the JS port.

  • The optimization step is seeded with a random embedding rather than a spectral embedding. This gives comparable results for smaller datasets. The spectral embedding computation relies on efficient eigenvalue / eigenvector computations that are not easily done in JS.
  • There is no specialized functionality for angular distances or sparse data representations.



yarn add umap-js

Synchronous fitting

import { UMAP } from 'umap-js';

const umap = new UMAP(); const embedding =;

Asynchronous fitting

import { UMAP } from 'umap-js';

const umap = new UMAP(); const embedding = await umap.fitAsync(data, epochNumber => { // check progress and give user feedback, or return false to stop });

Step-by-step fitting

import { UMAP } from 'umap-js';

const umap = new UMAP(); const nEpochs = umap.initializeFit(data); for (let i = 0; i < nEpochs; i++) { umap.step(); } const embedding = umap.getEmbedding();

Supervised projection using labels

import { UMAP } from 'umap-js';

const umap = new UMAP(); umap.setSupervisedProjection(labels); const embedding =;

Transforming additional points after fitting

import { UMAP } from 'umap-js';

const umap = new UMAP();; const transformed = umap.transform(additionalData);


The UMAP constructor can accept a number of hyperparameters via a

object, with the most common described below. See umap.ts for more details.

| Parameter | Description | default | | ------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | |

| The number of components (dimensions) to project the data to | 2 | |
| The number of epochs to optimize embeddings via SGD | (computed automatically) | |
| The number of nearest neighbors to construct the fuzzy manifold | 15 | |
| The effective minimum distance between embedded points, used with
to control the clumped/dispersed nature of the embedding | 0.1 | |
| The effective scale of embedded points, used with
to control the clumped/dispersed nature of the embedding | 1.0 | |
| A pseudo-random-number generator for controlling stochastic processes |
| |
| A custom distance function to use |
const umap = new UMAP({
  nComponents: 2,
  nEpochs: 400,
  nNeighbors: 15,


for testing.
yarn test

This is not an officially supported Google product

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.