umap-js icon indicating copy to clipboard operation
umap-js copied to clipboard

Loading fitted model to transform later

Open josesho opened this issue 7 months ago • 0 comments

I want to basically transform additional points after performing an initial fitting, but with a fitted model I load instead of one I just generated.

I tried to use class-transformer but got several errors.

So I tried the "manual" method of using JSON.stringify() on a already fitted UMAP model, then

const new = new UMAP({
    nComponents: 2,
    minDist: 0.5,
    scale: 1,
    nNeighbors: 2,
    distanceFn: dist.similarity.manhattan
  });

  Object.keys(loaded).map((x) => (n[x] = stringfiedUMAP[x]));

This new object does have an transform function as expected, but calling it with

n.transform([myNewVector])

gives the error

TypeError: initFromRandom is not a function

Any help or tips here would be appreciated! Ideally it would be nice to be able to load a prefitted UMAP and transform new data points, just like MacInnes' Python implementation.

Thanks in advance!

josesho avatar Apr 16 '25 11:04 josesho