Created
August 1, 2017 09:32
-
-
Save victorkohler/c168b211b7e16b0eee99e734d9521cc1 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
#------------------------ | |
# USER-ITEM CALCULATIONS | |
#------------------------ | |
user = 5985 # The id of the user for whom we want to generate recommendations | |
user_index = data[data.user == user].index.tolist()[0] # Get the frame index | |
# Get the artists the user has likd. | |
known_user_likes = data_items.ix[user_index] | |
known_user_likes = known_user_likes[known_user_likes >0].index.values | |
# Users likes for all items as a sparse vector. | |
user_rating_vector = data_items.ix[user_index] | |
# Calculate the score. | |
score = data_matrix.dot(user_rating_vector).div(data_matrix.sum(axis=1)) | |
# Remove the known likes from the recommendation. | |
score = score.drop(known_user_likes) | |
# Print the known likes and the top 20 recommendations. | |
print known_user_likes | |
print score.nlargest(20) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment