0

I am running a UMAP model as follows:

    embedding = umap.UMAP(n_components=2,n_neighbors=30, min_dist=0.0, metric='euclidean').fit(data)

And plotting:

    f = umap.plot.points(embedding, labels=df['name'])

This generates a nice looking graph. I'd like to get the coordinates of the points plotted, to move to a different visualisation. I don't fully understand what is stored in the embedding object.

Is there a way I can export to something like:

    [{'name': name1, 'x-value': x1, 'y-value': y1}, {'name': name2, 'x-value': x2, 'y-value': y2 }...] 

Or similar?

2 Answers 2

1

You can get an array of the x,y coordinates by doing

    embedding.embedding_

Not sure how I missed that.

0

One option would be to create a DataFrame with coordinates, add a column with the names, and turn it into a list of dicts.

It seems like you already have a DataFrame with the column name. If that's the case, I'd go for something like:

import pandas as pd

# Add coordinates into a Df
df_c = pd.DataFrame(embedding.embedding_)

# Add column with names
df_c['name'] = df['name']

# Transform Df into list of dicts
df_c.to_dict('records') 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.