Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def get_similar_movies(movie_title, n_ratings_filter=100, n_recommendations=5):
  2. similar = matrix.corrwith(matrix[movie_title])
  3. corr_similar = pd.DataFrame(similar, columns=['correlation'])
  4. corr_similar.dropna(inplace=True)
  5.  
  6. orig = data.copy()
  7.  
  8. corr_with_movie = pd.merge(
  9. left=corr_similar,
  10. right=orig,
  11. on='title')[['title', 'correlation', 'numRatings']].drop_duplicates().reset_index(drop=True)
  12.  
  13. result = corr_with_movie[corr_with_movie['numRatings'] > n_ratings_filter].sort_values(by='correlation', ascending=False)
  14.  
  15. return result.head(n_recommendations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement