Skip to content

Instantly share code, notes, and snippets.

@astoeckl
Last active December 12, 2021 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astoeckl/35b9a71f7f066e2bd18b8c1af1ef38a9 to your computer and use it in GitHub Desktop.
Save astoeckl/35b9a71f7f066e2bd18b8c1af1ef38a9 to your computer and use it in GitHub Desktop.
import seaborn as sns
from sklearn.manifold import TSNE
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (15, 8)
tsne = TSNE(n_components=2, perplexity=15, random_state=42, init='random', learning_rate=200)
vis_dims2 = tsne.fit_transform(matrix)
x = [x for x,y in vis_dims2]
y = [y for x,y in vis_dims2]
palette = sns.color_palette("inferno", 20).as_hex()
for category, color in enumerate(palette):
xs = np.array(x)[df.Cluster==category]
ys = np.array(y)[df.Cluster==category]
plt.scatter(xs, ys, color=color, alpha=0.1)
avg_x = xs.mean()
avg_y = ys.mean()
plt.scatter(avg_x, avg_y, marker='x', color=color, s=100)
plt.title("Embeddings visualized using t-SNE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment