Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_similar_movies(movie_title, n_ratings_filter=100, n_recommendations=5):
- similar = matrix.corrwith(matrix[movie_title])
- corr_similar = pd.DataFrame(similar, columns=['correlation'])
- corr_similar.dropna(inplace=True)
- orig = data.copy()
- corr_with_movie = pd.merge(
- left=corr_similar,
- right=orig,
- on='title')[['title', 'correlation', 'numRatings']].drop_duplicates().reset_index(drop=True)
- result = corr_with_movie[corr_with_movie['numRatings'] > n_ratings_filter].sort_values(by='correlation', ascending=False)
- return result.head(n_recommendations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement