Last active
August 17, 2017 08:40
-
-
Save victorkohler/54323b787ca0741cd07d896890ec7d03 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
#------------------------------ | |
# 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