-
-
Save amankharwal/129cef01e271bbca7879554cbd62e7f3 to your computer and use it in GitHub Desktop.
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
df_p = pd.pivot_table(df,values='Rating',index='Cust_Id',columns='Movie_Id') | |
df_title = pd.read_csv('../input/movie_titles.csv', encoding = "ISO-8859-1", header = None, names = ['Movie_Id', 'Year', 'Name']) | |
df_title.set_index('Movie_Id', inplace = True) | |
def recommend(movie_title, min_count): | |
print("For movie ({})".format(movie_title)) | |
print("- Top 10 movies recommended based on Pearsons'R correlation - ") | |
i = int(df_title.index[df_title['Name'] == movie_title][0]) | |
target = df_p[i] | |
similar_to_target = df_p.corrwith(target) | |
corr_target = pd.DataFrame(similar_to_target, columns = ['PearsonR']) | |
corr_target.dropna(inplace = True) | |
corr_target = corr_target.sort_values('PearsonR', ascending = False) | |
corr_target.index = corr_target.index.map(int) | |
corr_target = corr_target.join(df_title).join(df_movie_summary)[['PearsonR', 'Name', 'count', 'mean']] | |
print(corr_target[corr_target['count']>min_count][:10].to_string(index=False)) | |
recommend("What the #$*! Do We Know!?", 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment