Spaces:
Sleeping
Sleeping
edit data
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ data = pd.read_csv(r"data_final.csv")
|
|
7 |
def product_recommender(customer_id):
|
8 |
list_predicted = []
|
9 |
|
10 |
-
for id in
|
11 |
preds = list(algo.predict(customer_id, id))
|
12 |
product_id = preds[1]
|
13 |
product_score = preds[3]
|
@@ -17,11 +17,11 @@ def product_recommender(customer_id):
|
|
17 |
top_5_products_raw = sorted(list_predicted, key=lambda x:x[1], reverse=True)[:5]
|
18 |
top_5_products = [product[0] for product in top_5_products_raw]
|
19 |
|
20 |
-
product_1_category =
|
21 |
-
product_2_category =
|
22 |
-
product_3_category =
|
23 |
-
product_4_category =
|
24 |
-
product_5_category =
|
25 |
|
26 |
result_1 = f"Recommendation Product ID {top_5_products[0]} with Category {product_1_category}"
|
27 |
result_2 = f"Recommendation Product ID {top_5_products[1]} with Category {product_2_category}"
|
|
|
7 |
def product_recommender(customer_id):
|
8 |
list_predicted = []
|
9 |
|
10 |
+
for id in data['product_id'].unique():
|
11 |
preds = list(algo.predict(customer_id, id))
|
12 |
product_id = preds[1]
|
13 |
product_score = preds[3]
|
|
|
17 |
top_5_products_raw = sorted(list_predicted, key=lambda x:x[1], reverse=True)[:5]
|
18 |
top_5_products = [product[0] for product in top_5_products_raw]
|
19 |
|
20 |
+
product_1_category = data[data['product_id']==top_5_products[0]]['category'].values[0]
|
21 |
+
product_2_category = data[data['product_id']==top_5_products[1]]['category'].values[0]
|
22 |
+
product_3_category = data[data['product_id']==top_5_products[2]]['category'].values[0]
|
23 |
+
product_4_category = data[data['product_id']==top_5_products[3]]['category'].values[0]
|
24 |
+
product_5_category = data[data['product_id']==top_5_products[4]]['category'].values[0]
|
25 |
|
26 |
result_1 = f"Recommendation Product ID {top_5_products[0]} with Category {product_1_category}"
|
27 |
result_2 = f"Recommendation Product ID {top_5_products[1]} with Category {product_2_category}"
|