Skip to content

Instantly share code, notes, and snippets.

@victorkohler
Last active August 17, 2017 08:40
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/54323b787ca0741cd07d896890ec7d03 to your computer and use it in GitHub Desktop.
Save victorkohler/54323b787ca0741cd07d896890ec7d03 to your computer and use it in GitHub Desktop.
#------------------------------
# FIND SIMILAR ITEMS
#------------------------------
# Let's find similar artists to Jay-Z.
# Note that this ID might be different for you if you're using
# the full dataset or if you've sliced it somehow.
item_id = 10277
# Get the item row for Jay-Z
item_vec = item_vecs[item_id].T
# Calculate the similarity score between Mr Carter and other artists
# and select the top 10 most similar.
scores = item_vecs.dot(item_vec).toarray().reshape(1,-1)[0]
top_10 = np.argsort(scores)[::-1][:10]
artists = []
artist_scores = []
# Get and print the actual artists names and scores
for idx in top_10:
artists.append(item_lookup.artist.loc[item_lookup.artist_id == str(idx)].iloc[0])
artist_scores.append(scores[idx])
similar = pd.DataFrame({'artist': artists, 'score': artist_scores})
print similar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment