Created
January 16, 2022 08:34
-
-
Save susanli2016/ca72c229c49de7ff004527c2f9a4b3ac 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
item_id = 1319 | |
n_similar = 10 | |
item_vecs = model.item_factors | |
customer_vecs = model.user_factors | |
item_norms = np.sqrt((item_vecs * item_vecs).sum(axis=1)) | |
scores = item_vecs.dot(item_vecs[item_id]) / item_norms | |
top_idx = np.argpartition(scores, -n_similar)[-n_similar:] | |
similar = sorted(zip(top_idx, scores[top_idx] / item_norms[item_id]), key=lambda x: -x[1]) | |
for item in similar: | |
idx, score = item | |
print(grouped_df.Description.loc[grouped_df.item_id == idx].iloc[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment