concept UMAP in category R

appears as: UMAP, UMAP
Machine Learning with R, the tidyverse, and mlr

This is an excerpt from Manning's book Machine Learning with R, the tidyverse, and mlr.

UMAP is another nonlinear dimension-reduction algorithm that overcomes some of the limitations of t-SNE. It works similarly to t-SNE (finds distances in a feature space with many variables and then tries to reproduce these distances in low-dimensional space), but differs in the way it measures distances.

Figure 14.8. How UMAP learns a manifold. UMAP expands a search region around each case. A naive form of this is shown in the top row, where the radius of each search region is the same. When cases with overlapping search regions are connected by edges, there are gaps in the manifold. In the bottom row, the search region extends to the nearest neighbor and then extends outward in a fuzzy way, with a radius inversely related to the density of data in that region. This results in a complete manifold.

Real-world data is rarely evenly distributed, and UMAP solves this problem in two ways. First, it expands each search region for each case until it meets its nearest neighbor. This ensures that there are no orphan cases: while there can be multiple, disconnected manifolds in a dataset, every case must connect to at least one other case. Second, UMAP creates an additional search region that has a larger radius in lower-density areas and a smaller radius in high-density regions. These search regions are described as fuzzy, in that the further from the center another case finds itself, the lower the probability that an edge exists between those cases. This forces an artificial uniform distribution of the cases (and is where the “uniform” in UMAP comes from). This process is represented in the lower row of figure 14.8; notice that we now get a more complete estimation of the underlying manifold.

The next step is to place the data onto a new manifold in (usually) two new dimensions. Then the algorithm iteratively shuffles this new manifold around until the distances between the cases along the manifold look like the distances between the cases along the original, high-dimensional manifold. This is similar to the optimization step of t-SNE, except that UMAP minimizes a different loss function called cross-entropy (whereas t-SNE minimizes KL divergence).

I hope that demystifies UMAP’s hyperparameters a little. Now let’s run UMAP on our Swiss banknote dataset. Just like before, we first select all the columns except the categorical variable (UMAP cannot currently handle categorical variables, but this may change in the future) and pipe this data into the as.matrix() function (just to prevent an irritating warning message). This matrix is then piped into the umap() function, within which we manually set the values of all four hyperparameters and set the argument verbose = TRUE so the algorithm prints a running commentary on the number of epochs (iterations) that have passed.

Listing 14.3. Performing UMAP
swissUmap <- select(swissTib, -Status) %>%
             as.matrix() %>%
             umap(n_neighbors = 7, min_dist = 0.1,
                  metric = "manhattan", n_epochs = 200, verbose = TRUE)
  • UMAP can make predictions on new data.
  • UMAP is computationally inexpensive.