-1
Làm sao để kết quả không bị trùng lập
Tôi có một đoạn code như thế này
product_df = pd.read_csv("/content/drive/MyDrive/Dean3/Rating_product_title2.txt")
product_not_rating = product_df[
~product_df["ProductId"].isin(products_rating_by_user.ProductId.values)
]["ProductId"]
product_not_rating = list(
set(product_not_rating).intersection(set(product2product_encoded.keys()))
)
product_not_rating = [[product2product_encoded.get(x)] for x in product_not_rating]
user_encoder = user2user_encoded.get(user_id)
user_product_array = np.hstack(
([[user_encoder]] * len(product_not_rating), product_not_rating)
)
ratings = model.predict(user_product_array).flatten()
top_ratings_indices = ratings.argsort()[-5:][::-1]
recommended_product_ids = [
product_encoded2product.get(product_not_rating[x][0]) for x in top_ratings_indices
]
print("Showing recommendations for user: {}".format(user_id))
print("====" * 9)
print("Product with high ratings from user")
print("----" * 8)
top_product_user = (
products_rating_by_user.sort_values(by="Rating", ascending=False)
.head(5)
.ProductId.values
)
product_df_rows = product_df[product_df["ProductId"].isin(top_product_user)]
for row in product_df_rows.itertuples():
print(row.ProductId, ":", row.Title)
print("----" * 8)
print("Top 5 product recommendations")
print("----" * 8)
recommended_products = product_df[product_df["ProductId"].isin(recommended_product_ids)]
for row in recommended_products.itertuples():
print(row.ProductId, ":", row.Title)
Và kết quả tôi nhân được là
6/6 [==============================] - 0s 2ms/step
Showing recommendations for user: 56
====================================
Product with high ratings from user
--------------------------------
1304511154 : Mac Magic N 8 Leopard 12 Eyeshadow Palette European Collection
1304511154 : Mac Magic N 8 Leopard 12 Eyeshadow Palette European Collection
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
6022600685 : Professional Hair Stylist Aluminum Rolling Tool Box Makeup Artist Salon Train Case
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9511181564 : 33.8 Fluid Oz Shower Gel
9788071538 : Sim plus Men's online shopping
9788071538 : Sim plus Men's online shopping
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
9788074359 : Organization Performance And System Choice (2019)
--------------------------------
Top 5 product recommendations
--------------------------------
4057362886 : Instyle Perfume Sex In City Desire Eau de Parfum Spray for Women 100 ml
5357955867 : Starter Retail Products Details 16303a1f-d
5357955867 : Starter Retail Products Details 16303a1f-d
5357955867 : Starter Retail Products Details 16303a1f-d
5357955867 : Starter Retail Products Details 16303a1f-d
5357955867 : Starter Retail Products Details 16303a1f-d
9602617918 : Q10 Skin Solution Anti-Aging Multi-Active
9602617918 : Q10 Skin Solution Anti-Aging Multi-Active
9602617918 : Q10 Skin Solution Anti-Aging Multi-Active
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788073476 : New Item VIKTOR & ROLPH SPICEBOMB EDT SPRAY 3.0
9788074286 : Organization Performance And System Choice (2019)
9788074286 : Organization Performance And System Choice (2019)
9788074286 : Organization Performance And System Choice (2019)
9788074286 : Organization Performance And System Choice (2019)
9788074286 : Organization Performance And System Choice (2019)
9788074286 : Organization Performance And System Choice (2019)
Làm sao để kết quả không bị trùng lặp vậy ?
Thêm một bình luận
1 CÂU TRẢ LỜI
0
Đoạn code trên dùng để làm gì? Bạn có thể giải thích từng bước trong đoạn code đó không? (Ngữ cảnh của bạn là gì? bạn đang làm gì?... hoặc ít nhất cũng là 1 đoạn code hoàn chỉnh thì mn mới giúp bạn được)