Home

Awesome

Build Status

UMAP-JS

This is a JavaScript reimplementation of UMAP from the python implementation found at https://github.com/lmcinnes/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.

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

Usage

Installation

yarn add umap-js

Synchronous fitting

import { UMAP } from 'umap-js';

const umap = new UMAP();
const embedding = umap.fit(data);

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 = umap.fit(data);

Transforming additional points after fitting

import { UMAP } from 'umap-js';

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

Parameters

The UMAP constructor can accept a number of hyperparameters via a UMAPParameters object, with the most common described below. See umap.ts for more details.

ParameterDescriptiondefault
nComponentsThe number of components (dimensions) to project the data to2
nEpochsThe number of epochs to optimize embeddings via SGD(computed automatically)
nNeighborsThe number of nearest neighbors to construct the fuzzy manifold15
minDistThe effective minimum distance between embedded points, used with spread to control the clumped/dispersed nature of the embedding0.1
spreadThe effective scale of embedded points, used with minDist to control the clumped/dispersed nature of the embedding1.0
randomA pseudo-random-number generator for controlling stochastic processesMath.random
distanceFnA custom distance function to useeuclidean
const umap = new UMAP({
  nComponents: 2,
  nEpochs: 400,
  nNeighbors: 15,
});

Testing

umap-js uses jest for testing.

yarn test

This is not an officially supported Google product