Skip to content

Instantly share code, notes, and snippets.

@andrea-dagostino
Last active October 3, 2022 22:16
Show Gist options
  • Save andrea-dagostino/968dfc3a1b6f54feb0e476069d4e3456 to your computer and use it in GitHub Desktop.
Save andrea-dagostino/968dfc3a1b6f54feb0e476069d4e3456 to your computer and use it in GitHub Desktop.
text_sim_tfidf
labels = posts.url.str.split('/').str[3:].str[1] # we extract the titles of the articles from the url
similarity_df = pd.DataFrame(M, columns=labels, index=labels) # let's create the dataframe
mask = np.triu(np.ones_like(similarity_df)) # we apply a mask to remove the top of the heatmap
# let's create the viz
plt.figure(figsize=(12, 12))
sns.heatmap(
similarity_df,
square=True,
annot=True,
robust=True,
fmt='.2f',
annot_kws={'size': 7, 'fontweight': 'bold'},
yticklabels=similarity_df.columns
xticklabels=similarity_df.columns,
cmap="YlGnBu",
mask=mask
)
plt.title('Similarity heatmap', fontdict={'fontsize': 24})
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment