Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorkohler/c168b211b7e16b0eee99e734d9521cc1 to your computer and use it in GitHub Desktop.
Save victorkohler/c168b211b7e16b0eee99e734d9521cc1 to your computer and use it in GitHub Desktop.
#------------------------
# 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