Created
April 16, 2022 13:52
-
-
Save srang992/9f4ff0a808055423adc15f647deb09ae to your computer and use it in GitHub Desktop.
recommend movies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recommend_table(list_of_movie_enjoyed, tfidf_data, movie_count=20): | |
""" | |
function for recommending movies | |
:param list_of_movie_enjoyed: list of movies | |
:param tfidf_data: self-explanatory | |
:param movie_count: no of movies to suggest | |
:return: dataframe containing suggested movie | |
""" | |
movie_enjoyed_df = tfidf_data.reindex(list_of_movie_enjoyed) | |
user_prof = movie_enjoyed_df.mean() | |
tfidf_subset_df = tfidf_data.drop(list_of_movie_enjoyed) | |
similarity_array = cosine_similarity(user_prof.values.reshape(1, -1), tfidf_subset_df) | |
similarity_df = pd.DataFrame(similarity_array.T, index=tfidf_subset_df.index, columns=["similarity_score"]) | |
sorted_similarity_df = similarity_df.sort_values(by="similarity_score", ascending=False).head(movie_count) | |
return sorted_similarity_df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment