Skip to content

Instantly share code, notes, and snippets.

@tomasonjo
Created June 28, 2022 10:05
Show Gist options
  • Save tomasonjo/df50a40dd921ccc94a74c0d65e5f29fa to your computer and use it in GitHub Desktop.
Save tomasonjo/df50a40dd921ccc94a74c0d65e5f29fa to your computer and use it in GitHub Desktop.
from sklearn.manifold import TSNE
from sklearn.preprocessing import StandardScaler
tsne_data = merged_df.drop(["nodeId", "communityId"], axis=1).values.tolist()
scaler = StandardScaler()
scaler.fit(tsne_data)
tsne = TSNE(
n_components=2, n_iter=500, random_state=42, perplexity=50, learning_rate=20
)
tsne_results = tsne.fit_transform(scaler.transform(tsne_data))
merged_df["tsne_x"] = [x[0] for x in list(tsne_results)]
merged_df["tsne_y"] = [x[1] for x in list(tsne_results)]
plt.figure(figsize=(18, 10))
sns.scatterplot(
x="tsne_x",
y="tsne_y",
hue="communityId",
palette=sns.color_palette("hls", 6),
data=merged_df,
legend="full",
alpha=0.9,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment