Skip to content

Instantly share code, notes, and snippets.

@ikatsov
Created March 15, 2020 15:57
Show Gist options
  • Save ikatsov/5f13d62a7da6726ae9cb3e966a64a201 to your computer and use it in GitHub Desktop.
Save ikatsov/5f13d62a7da6726ae9cb3e966a64a201 to your computer and use it in GitHub Desktop.
def to_product_name(id, columns='product_name'):
Return products_csv[products_csv.product_id==id][columns].values.tolist()[0]
def most_similar_readable(model, product_id, topn=10):
similar_list = [(product_id, 1.0)] + model.wv.most_similar(str(product_id),
topn=topn)
return pd.DataFrame([( to_product_name(int(id)), int(id), similarity ) for
(id, similarity) in similar_list],
columns=['product', 'product_id', 'similarity'])
for product_id in [13176, # Bag of Organic Bananas
39180, # Organic Lowfat 1% Milk
2326]: # Organic Blueberry Waffles
most_similar_readable(model, product_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment