Skip to content

Instantly share code, notes, and snippets.

@MathiasGruber
Last active April 7, 2021 08:34
Show Gist options
  • Save MathiasGruber/dc344907ce64ae318da0c5eaf0301027 to your computer and use it in GitHub Desktop.
Save MathiasGruber/dc344907ce64ae318da0c5eaf0301027 to your computer and use it in GitHub Desktop.
Running t-SNE, UMAP, TriMAP and PaCMAP
import time
import trimap
import umap
import pacmap
from sklearn.manifold import TSNE
# Read data
df = pd.read_csv('your_dataset.csv')
# Algorithms to test
algorithms = {
't-SNE': TSNE(),
'UMAP': umap.UMAP(),
'TriMAP': trimap.TRIMAP(),
'PaCMAP': pacmap.PaCMAP()
}
# Create embeddings for each algorithm & save fitting time
results = {}
for name, algorithm in algorithms.items():
# Calculate embeddings
t0 = time.time()
embedding = algorithm.fit_transform(df.values)
# Store results & runtime
results[name] = {
'embedding': pd.DataFrame(embedding, columns=['x', 'y']),
'time': time.time() - t0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment