lmcinnes / lmcinnes/umap

Shift of UMAP points when using .transform()

Open
#755 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.3k
Forks
871
Avg merge
1d 13h
Merged PRs (30d)
5

Description

Hi,
I am encountering a point shift issue when fitting umap to embeddings X_train and then applying the fit to embeddings X_test not seen during training.

Here is an example data set creation to demonstrate the issue:

The new points are all shifted to the bottom left corner of the UMAP space:
![image](https://user-images.githubusercontent.com/34402894/131858630-4acd13a2-906c-4c9a-9ff3-b347bbd12b33.png)

This is the code for the example above
```import numpy as np
import pandas as pd
import plotly.express as px
from umap import UMAP
n_examples = 1000
X = np.random.random((n_examples,128))
X_train = X[:n_examples//2]
X_test = X[n_examples//2:]
mapper = UMAP()
mapper.fit(X_train)
low_dim_emb_train = mapper.transform(X_train)
low_dim_emb_test = mapper.transform(X_test)
df_train = pd.DataFrame({"x":low_dim_emb_train[:,0],"y":low_dim_emb_train[:,1],"dataset":["train"]*len(low_dim_emb_train)})
df_test = pd.DataFrame({"x":low_dim_emb_test[:,0],"y":low_dim_emb_test[:,1],"dataset":["test"]*len(low_dim_emb_test)})
df_plot = pd.concat([df_train,df_test])
px.scatter(df_plot,x="x",y="y",color="dataset")
```

What could be the issue?
Many thanks
Olivia

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Python reproducer with UMAP.fit() on X_train and transform() on both X_train and X_test, then inspect the transform behavior and related UMAP implementation entry points. Done means explaining or correcting the reported bottom-left shift for unseen points and adding a regression check for the demonstrated case; no specific file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, plotly, python
Domain
data-visualization, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.