Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created June 2, 2022 21:31
Show Gist options
  • Save Steboss89/17e9ceb11170a6c98b32a779c0cab8fd to your computer and use it in GitHub Desktop.
Save Steboss89/17e9ceb11170a6c98b32a779c0cab8fd to your computer and use it in GitHub Desktop.
def create_heatmap(similarity, cmap = "YlGnBu"):
df = pd.DataFrame(similarity)
df.columns = ['john', 'luke','mark', 'matt'] #ohn 0 mark 2 matt 3 luke 1
df.index = ['john', 'luke','mark', 'matt']
fig, ax = plt.subplots(figsize=(5,5))
sns.heatmap(df, cmap=cmap)
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import TfidfVectorizer
import seaborn as sns
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(data)
arr = X.toarray()
create_heatmap(cosine_similarity(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment