Last active
October 3, 2022 22:16
-
-
Save andrea-dagostino/968dfc3a1b6f54feb0e476069d4e3456 to your computer and use it in GitHub Desktop.
text_sim_tfidf
This file contains hidden or 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
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