Spaces:
Sleeping
Sleeping
Debugging
Browse files- DF_Construction.ipynb +11 -11
- __pycache__/recommender.cpython-38.pyc +0 -0
- app.py +3 -3
- items_0.csv +0 -0
- items_1.csv +0 -0
- items_2.csv +0 -0
- items_3.csv +0 -0
- items_4.csv +0 -0
- recommender.py +19 -4
- users_0.csv +0 -0
- users_1.csv +0 -0
- users_10.csv +0 -0
- users_11.csv +0 -0
- users_2.csv +0 -0
- users_3.csv +0 -0
- users_4.csv +0 -0
- users_5.csv +0 -0
- users_6.csv +0 -0
- users_7.csv +0 -0
- users_8.csv +0 -0
- users_9.csv +0 -0
DF_Construction.ipynb
CHANGED
@@ -2899,7 +2899,7 @@
|
|
2899 |
},
|
2900 |
{
|
2901 |
"cell_type": "code",
|
2902 |
-
"execution_count":
|
2903 |
"id": "05811f9a",
|
2904 |
"metadata": {},
|
2905 |
"outputs": [],
|
@@ -2929,7 +2929,7 @@
|
|
2929 |
},
|
2930 |
{
|
2931 |
"cell_type": "code",
|
2932 |
-
"execution_count":
|
2933 |
"id": "78eb378f",
|
2934 |
"metadata": {},
|
2935 |
"outputs": [
|
@@ -2939,7 +2939,7 @@
|
|
2939 |
"42"
|
2940 |
]
|
2941 |
},
|
2942 |
-
"execution_count":
|
2943 |
"metadata": {},
|
2944 |
"output_type": "execute_result"
|
2945 |
}
|
@@ -2953,7 +2953,7 @@
|
|
2953 |
},
|
2954 |
{
|
2955 |
"cell_type": "code",
|
2956 |
-
"execution_count":
|
2957 |
"id": "b7a07409",
|
2958 |
"metadata": {},
|
2959 |
"outputs": [
|
@@ -2982,7 +2982,7 @@
|
|
2982 |
" filename = \"users_{}.csv\".format(part)\n",
|
2983 |
" start_idx = part * n_rows\n",
|
2984 |
" end_idx = min((part+1) * n_rows, users_df.shape[0])\n",
|
2985 |
-
" users_df.loc[start_idx:
|
2986 |
]
|
2987 |
},
|
2988 |
{
|
@@ -2996,7 +2996,7 @@
|
|
2996 |
},
|
2997 |
{
|
2998 |
"cell_type": "code",
|
2999 |
-
"execution_count":
|
3000 |
"id": "101ade69",
|
3001 |
"metadata": {},
|
3002 |
"outputs": [
|
@@ -3006,7 +3006,7 @@
|
|
3006 |
"9015"
|
3007 |
]
|
3008 |
},
|
3009 |
-
"execution_count":
|
3010 |
"metadata": {},
|
3011 |
"output_type": "execute_result"
|
3012 |
}
|
@@ -3020,7 +3020,7 @@
|
|
3020 |
},
|
3021 |
{
|
3022 |
"cell_type": "code",
|
3023 |
-
"execution_count":
|
3024 |
"id": "35266a30",
|
3025 |
"metadata": {},
|
3026 |
"outputs": [
|
@@ -3042,7 +3042,7 @@
|
|
3042 |
" filename = \"items_{}.csv\".format(part)\n",
|
3043 |
" start_idx = part * n_rows\n",
|
3044 |
" end_idx = min((part+1) * n_rows, items_df.shape[0])\n",
|
3045 |
-
" items_df.loc[start_idx:
|
3046 |
]
|
3047 |
},
|
3048 |
{
|
@@ -3185,7 +3185,7 @@
|
|
3185 |
},
|
3186 |
{
|
3187 |
"cell_type": "code",
|
3188 |
-
"execution_count":
|
3189 |
"id": "ac68d277",
|
3190 |
"metadata": {},
|
3191 |
"outputs": [
|
@@ -3307,7 +3307,7 @@
|
|
3307 |
"[2 rows x 30 columns]"
|
3308 |
]
|
3309 |
},
|
3310 |
-
"execution_count":
|
3311 |
"metadata": {},
|
3312 |
"output_type": "execute_result"
|
3313 |
}
|
|
|
2899 |
},
|
2900 |
{
|
2901 |
"cell_type": "code",
|
2902 |
+
"execution_count": 39,
|
2903 |
"id": "05811f9a",
|
2904 |
"metadata": {},
|
2905 |
"outputs": [],
|
|
|
2929 |
},
|
2930 |
{
|
2931 |
"cell_type": "code",
|
2932 |
+
"execution_count": 40,
|
2933 |
"id": "78eb378f",
|
2934 |
"metadata": {},
|
2935 |
"outputs": [
|
|
|
2939 |
"42"
|
2940 |
]
|
2941 |
},
|
2942 |
+
"execution_count": 40,
|
2943 |
"metadata": {},
|
2944 |
"output_type": "execute_result"
|
2945 |
}
|
|
|
2953 |
},
|
2954 |
{
|
2955 |
"cell_type": "code",
|
2956 |
+
"execution_count": 42,
|
2957 |
"id": "b7a07409",
|
2958 |
"metadata": {},
|
2959 |
"outputs": [
|
|
|
2982 |
" filename = \"users_{}.csv\".format(part)\n",
|
2983 |
" start_idx = part * n_rows\n",
|
2984 |
" end_idx = min((part+1) * n_rows, users_df.shape[0])\n",
|
2985 |
+
" users_df.loc[start_idx:end_idx].to_csv(filename, index=None)"
|
2986 |
]
|
2987 |
},
|
2988 |
{
|
|
|
2996 |
},
|
2997 |
{
|
2998 |
"cell_type": "code",
|
2999 |
+
"execution_count": 35,
|
3000 |
"id": "101ade69",
|
3001 |
"metadata": {},
|
3002 |
"outputs": [
|
|
|
3006 |
"9015"
|
3007 |
]
|
3008 |
},
|
3009 |
+
"execution_count": 35,
|
3010 |
"metadata": {},
|
3011 |
"output_type": "execute_result"
|
3012 |
}
|
|
|
3020 |
},
|
3021 |
{
|
3022 |
"cell_type": "code",
|
3023 |
+
"execution_count": 36,
|
3024 |
"id": "35266a30",
|
3025 |
"metadata": {},
|
3026 |
"outputs": [
|
|
|
3042 |
" filename = \"items_{}.csv\".format(part)\n",
|
3043 |
" start_idx = part * n_rows\n",
|
3044 |
" end_idx = min((part+1) * n_rows, items_df.shape[0])\n",
|
3045 |
+
" items_df.loc[start_idx:end_idx].to_csv(filename, index=None)"
|
3046 |
]
|
3047 |
},
|
3048 |
{
|
|
|
3185 |
},
|
3186 |
{
|
3187 |
"cell_type": "code",
|
3188 |
+
"execution_count": 22,
|
3189 |
"id": "ac68d277",
|
3190 |
"metadata": {},
|
3191 |
"outputs": [
|
|
|
3307 |
"[2 rows x 30 columns]"
|
3308 |
]
|
3309 |
},
|
3310 |
+
"execution_count": 22,
|
3311 |
"metadata": {},
|
3312 |
"output_type": "execute_result"
|
3313 |
}
|
__pycache__/recommender.cpython-38.pyc
ADDED
Binary file (7.71 kB). View file
|
|
app.py
CHANGED
@@ -24,7 +24,7 @@ with gr.Blocks(css=css) as demo:
|
|
24 |
|
25 |
# First Component
|
26 |
with gr.Column(scale=1):
|
27 |
-
col_1_number = gr.Number(value=
|
28 |
|
29 |
gr.Markdown("Based on similar movies...")
|
30 |
|
@@ -41,7 +41,7 @@ with gr.Blocks(css=css) as demo:
|
|
41 |
|
42 |
# Second Component
|
43 |
with gr.Column(scale=1):
|
44 |
-
col_2_number = gr.Number(value=
|
45 |
|
46 |
gr.Markdown("Based on similar users...")
|
47 |
|
@@ -58,7 +58,7 @@ with gr.Blocks(css=css) as demo:
|
|
58 |
|
59 |
# Third Component
|
60 |
with gr.Column(scale=1):
|
61 |
-
col_3_number = gr.Number(value=
|
62 |
|
63 |
gr.Markdown("Based on similar users and movies...")
|
64 |
|
|
|
24 |
|
25 |
# First Component
|
26 |
with gr.Column(scale=1):
|
27 |
+
col_1_number = gr.Number(value=0, visible=False)
|
28 |
|
29 |
gr.Markdown("Based on similar movies...")
|
30 |
|
|
|
41 |
|
42 |
# Second Component
|
43 |
with gr.Column(scale=1):
|
44 |
+
col_2_number = gr.Number(value=1, visible=False)
|
45 |
|
46 |
gr.Markdown("Based on similar users...")
|
47 |
|
|
|
58 |
|
59 |
# Third Component
|
60 |
with gr.Column(scale=1):
|
61 |
+
col_3_number = gr.Number(value=2, visible=False)
|
62 |
|
63 |
gr.Markdown("Based on similar users and movies...")
|
64 |
|
items_0.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
items_1.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
items_2.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
items_3.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
items_4.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
recommender.py
CHANGED
@@ -49,7 +49,7 @@ class ItemData:
|
|
49 |
return self.df[self.df['id'] == int(id)][self.item_columns]
|
50 |
|
51 |
def get_id_by_idx(self, idx):
|
52 |
-
return self.df.
|
53 |
|
54 |
def get_random_id(self):
|
55 |
return self.df.sample(1)['id'].values[0]
|
@@ -181,7 +181,7 @@ class Recommender:
|
|
181 |
cols_to_drop.append(best_movie)
|
182 |
continue
|
183 |
|
184 |
-
if self.user_handler.df.
|
185 |
return int(best_movie)
|
186 |
|
187 |
# Otherwise, return random movie
|
@@ -216,7 +216,7 @@ class Recommender:
|
|
216 |
continue
|
217 |
|
218 |
for user_id in user_idxs[0]:
|
219 |
-
score = self.user_handler.df.
|
220 |
if score != 0:
|
221 |
score_sums[i] += score
|
222 |
n_votes[i] += 1
|
@@ -233,4 +233,19 @@ class Recommender:
|
|
233 |
# Find best score
|
234 |
best_score_idx = final_score.index(max(final_score))
|
235 |
best_movie_idx = item_idxs[0][best_score_idx]
|
236 |
-
return self.item_handler.get_id_by_idx(best_movie_idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
return self.df[self.df['id'] == int(id)][self.item_columns]
|
50 |
|
51 |
def get_id_by_idx(self, idx):
|
52 |
+
return self.df.iloc[int(idx)]['id']
|
53 |
|
54 |
def get_random_id(self):
|
55 |
return self.df.sample(1)['id'].values[0]
|
|
|
181 |
cols_to_drop.append(best_movie)
|
182 |
continue
|
183 |
|
184 |
+
if self.user_handler.df.iloc[best_idx][best_movie] > 2.5:
|
185 |
return int(best_movie)
|
186 |
|
187 |
# Otherwise, return random movie
|
|
|
216 |
continue
|
217 |
|
218 |
for user_id in user_idxs[0]:
|
219 |
+
score = self.user_handler.df.iloc[user_id][str(movie_id)]
|
220 |
if score != 0:
|
221 |
score_sums[i] += score
|
222 |
n_votes[i] += 1
|
|
|
233 |
# Find best score
|
234 |
best_score_idx = final_score.index(max(final_score))
|
235 |
best_movie_idx = item_idxs[0][best_score_idx]
|
236 |
+
return self.item_handler.get_id_by_idx(best_movie_idx)
|
237 |
+
|
238 |
+
|
239 |
+
if __name__ == '__main__':
|
240 |
+
recommender = Recommender()
|
241 |
+
res = recommender.on_pick(0, 1)
|
242 |
+
print(res)
|
243 |
+
res = recommender.on_pick(0, 3.4)
|
244 |
+
print(res)
|
245 |
+
res = recommender.on_pick(1, 1)
|
246 |
+
print(res)
|
247 |
+
res = recommender.on_pick(1, 3.4)
|
248 |
+
print(res)
|
249 |
+
|
250 |
+
# print(recommender.item_handler.df.iloc[20712]['id'])
|
251 |
+
|
users_0.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_1.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_10.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_11.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_2.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_3.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_4.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_5.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_6.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_7.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_8.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
users_9.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|