Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.feature_extraction.text import TfidfVectorizer
- from sklearn.metrics.pairwise import cosine_similarity
- # Assume we have a pandas DataFrame df with movie titles and their descriptions
- vectorizer = TfidfVectorizer(stop_words='english')
- tfidf_matrix = vectorizer.fit_transform(df['description'])
- # Compute the cosine similarity matrix
- cosine_sim = cosine_similarity(tfidf_matrix, tfidf_matrix)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement