Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -212,6 +212,7 @@ cosine_sim = linear_kernel(tfidf_matrix, tfidf_matrix)
|
|
212 |
|
213 |
|
214 |
smd = smd.reset_index()
|
|
|
215 |
|
216 |
|
217 |
# In[24]:
|
@@ -224,25 +225,10 @@ indices = pd.Series(smd.index, index=smd['title'])
|
|
224 |
# In[25]:
|
225 |
|
226 |
|
227 |
-
tfidf_matrix.shape
|
228 |
|
229 |
|
230 |
-
# In[34]:
|
231 |
|
232 |
|
233 |
-
def get_recommendations(title):
|
234 |
-
if indices[title].shape ==():
|
235 |
-
idx = indices[title]
|
236 |
-
else:
|
237 |
-
idx = indices[title][0]
|
238 |
-
sim = cosine_sim
|
239 |
-
sim_scores = list(enumerate(sim[idx]))
|
240 |
-
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
241 |
-
sim_scores = sim_scores[1:5]
|
242 |
-
title_idx= [l[0] for l in sim_scores]
|
243 |
-
title_rec = [titles[i] for i in title_idx]
|
244 |
-
return title_rec
|
245 |
-
|
246 |
|
247 |
# In[28]:
|
248 |
|
@@ -253,7 +239,6 @@ def get_recommendations(title):
|
|
253 |
# In[27]:
|
254 |
|
255 |
|
256 |
-
#get_recommendations('The Dark Knight',cosine_sim)
|
257 |
|
258 |
|
259 |
# <b> <font size="3"> Adding the metadata to the rec system <font> <b>
|
@@ -388,6 +373,7 @@ cosine_sim2 = linear_kernel(count_matrix, count_matrix)
|
|
388 |
|
389 |
|
390 |
smd = smd.reset_index()
|
|
|
391 |
titles = smd['title']
|
392 |
indices = pd.Series(smd.index, index=smd['title'])
|
393 |
|
@@ -401,20 +387,7 @@ indices = pd.Series(smd.index, index=smd['title'])
|
|
401 |
# In[60]:
|
402 |
|
403 |
|
404 |
-
def get_recommendations(title,sim):
|
405 |
-
if indices[title].shape ==():
|
406 |
-
idx = indices[title]
|
407 |
-
else:
|
408 |
-
idx = indices[title][0]
|
409 |
-
sim_scores = list(enumerate(sim[idx]))
|
410 |
-
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
411 |
-
sim_scores = sim_scores[1:31]
|
412 |
-
title_idx= [l[0] for l in sim_scores]
|
413 |
-
title_rec = [titles[i] for i in title_idx]
|
414 |
-
return title_rec
|
415 |
-
|
416 |
|
417 |
-
# In[62]:
|
418 |
|
419 |
|
420 |
#get_recommendations('The Avengers',cosine_sim2)
|
@@ -426,6 +399,7 @@ def get_recommendations(title,sim):
|
|
426 |
|
427 |
|
428 |
def improved_recommendations(title):
|
|
|
429 |
idx = indices[title]
|
430 |
sim_scores = list(enumerate(cosine_sim2[idx]))
|
431 |
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
@@ -442,7 +416,7 @@ def improved_recommendations(title):
|
|
442 |
qualified['vote_average'] = qualified['vote_average'].astype('int')
|
443 |
qualified['wr'] = qualified.apply(weighted_rating, axis=1)
|
444 |
qualified = qualified.sort_values('wr', ascending=False).head(10)
|
445 |
-
return list(qualified['title'])
|
446 |
|
447 |
|
448 |
# In[76]:
|
|
|
212 |
|
213 |
|
214 |
smd = smd.reset_index()
|
215 |
+
smd['title'] = smd['title'].apply(lambda x: str.lower(x))
|
216 |
|
217 |
|
218 |
# In[24]:
|
|
|
225 |
# In[25]:
|
226 |
|
227 |
|
|
|
228 |
|
229 |
|
|
|
230 |
|
231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
# In[28]:
|
234 |
|
|
|
239 |
# In[27]:
|
240 |
|
241 |
|
|
|
242 |
|
243 |
|
244 |
# <b> <font size="3"> Adding the metadata to the rec system <font> <b>
|
|
|
373 |
|
374 |
|
375 |
smd = smd.reset_index()
|
376 |
+
smd['title'] = smd['title'].apply(lambda x: str.lower(x))
|
377 |
titles = smd['title']
|
378 |
indices = pd.Series(smd.index, index=smd['title'])
|
379 |
|
|
|
387 |
# In[60]:
|
388 |
|
389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
|
|
|
391 |
|
392 |
|
393 |
#get_recommendations('The Avengers',cosine_sim2)
|
|
|
399 |
|
400 |
|
401 |
def improved_recommendations(title):
|
402 |
+
title = str.lower(title)
|
403 |
idx = indices[title]
|
404 |
sim_scores = list(enumerate(cosine_sim2[idx]))
|
405 |
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
|
|
416 |
qualified['vote_average'] = qualified['vote_average'].astype('int')
|
417 |
qualified['wr'] = qualified.apply(weighted_rating, axis=1)
|
418 |
qualified = qualified.sort_values('wr', ascending=False).head(10)
|
419 |
+
return list(qualified['title'].apply(lambda x: x.title()))
|
420 |
|
421 |
|
422 |
# In[76]:
|