Advertisement
897bhgy

Untitled

Jul 24th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | Source Code | 0 0
  1. from sklearn.feature_extraction.text import TfidfVectorizer
  2. from sklearn.metrics.pairwise import cosine_similarity
  3.  
  4. # Assume we have a pandas DataFrame df with movie titles and their descriptions
  5. vectorizer = TfidfVectorizer(stop_words='english')
  6. tfidf_matrix = vectorizer.fit_transform(df['description'])
  7.  
  8. # Compute the cosine similarity matrix
  9. cosine_sim = cosine_similarity(tfidf_matrix, tfidf_matrix)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement