Update logic2.py
Browse files
logic2.py
CHANGED
@@ -75,6 +75,17 @@ def load_model(data):
|
|
75 |
model.eval()
|
76 |
return model
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
def get_recommendation(model,data,user_id):
|
79 |
|
80 |
total_movies = 9025
|
@@ -87,5 +98,6 @@ def get_recommendation(model,data,user_id):
|
|
87 |
# we will only select movies for the user where the predicting rating is =5
|
88 |
rec_movie_ids = (pred == 5).nonzero(as_tuple=True)
|
89 |
top_ten_recs = [rec_movies for rec_movies in rec_movie_ids[0].tolist()[:10]]
|
|
|
90 |
return {'user': user_id, 'rec_movies': top_ten_recs}
|
91 |
|
|
|
75 |
model.eval()
|
76 |
return model
|
77 |
|
78 |
+
global id_map
|
79 |
+
with open('id_map.pkl', 'rb') as file:
|
80 |
+
id_map = pickle.load(file)
|
81 |
+
|
82 |
+
global m_id
|
83 |
+
with open('m_id.pkl', 'rb') as file:
|
84 |
+
m_id = pickle.load(file)
|
85 |
+
|
86 |
+
def get_movie(idx):
|
87 |
+
return id_map.loc[id_map['movieId'] == m_id[idx]].index
|
88 |
+
|
89 |
def get_recommendation(model,data,user_id):
|
90 |
|
91 |
total_movies = 9025
|
|
|
98 |
# we will only select movies for the user where the predicting rating is =5
|
99 |
rec_movie_ids = (pred == 5).nonzero(as_tuple=True)
|
100 |
top_ten_recs = [rec_movies for rec_movies in rec_movie_ids[0].tolist()[:10]]
|
101 |
+
top_ten_recs = [get_movie(movie_idx) for movie_idx in top_ten_recs]
|
102 |
return {'user': user_id, 'rec_movies': top_ten_recs}
|
103 |
|