Last active
December 12, 2021 09:06
-
-
Save astoeckl/35b9a71f7f066e2bd18b8c1af1ef38a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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