AmirShabani
commited on
Commit
·
415bdb0
1
Parent(s):
b487903
List by name
Browse files
core.py
CHANGED
@@ -6,11 +6,11 @@ def install(package):
|
|
6 |
else:
|
7 |
pip._internal.main(['install', package])
|
8 |
|
9 |
-
print("Everything goes bang")
|
10 |
install('torch_geometric')
|
11 |
install('torch_scatter')
|
12 |
install('torch_sparse')
|
13 |
-
print("It's havoc baby")
|
14 |
|
15 |
import pickle
|
16 |
import numpy as np
|
@@ -158,7 +158,7 @@ def create_user_embedding(movie_ratings, movies_df):
|
|
158 |
user_ratings_df['movieId'] = user_ratings_df.index
|
159 |
|
160 |
# Merge the user_ratings_df with the movies_df to get the movie embeddings
|
161 |
-
user_movie_embeddings =
|
162 |
|
163 |
# Multiply the ratings with the movie embeddings
|
164 |
user_movie_embeddings = user_movie_embeddings.iloc[:, 2:].values * user_movie_embeddings['rating'].values[:, np.newaxis]
|
@@ -178,7 +178,16 @@ def find_closest_user(user_embedding, tree, user_embeddings):
|
|
178 |
|
179 |
return closest_user_embedding
|
180 |
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
user_embed = create_user_embedding(movie_ratings, movie_embeds)
|
183 |
# Call the find_closest_user function with the pre-built BallTree
|
184 |
closest_user_embed = find_closest_user(user_embed, tree, user_embeds)
|
|
|
6 |
else:
|
7 |
pip._internal.main(['install', package])
|
8 |
|
9 |
+
print("Everything goes bang.")
|
10 |
install('torch_geometric')
|
11 |
install('torch_scatter')
|
12 |
install('torch_sparse')
|
13 |
+
print("It's havoc baby!")
|
14 |
|
15 |
import pickle
|
16 |
import numpy as np
|
|
|
158 |
user_ratings_df['movieId'] = user_ratings_df.index
|
159 |
|
160 |
# Merge the user_ratings_df with the movies_df to get the movie embeddings
|
161 |
+
user_movie_embeddings = user_ratings_df.merge(movies_df, on='movieId', how='left')
|
162 |
|
163 |
# Multiply the ratings with the movie embeddings
|
164 |
user_movie_embeddings = user_movie_embeddings.iloc[:, 2:].values * user_movie_embeddings['rating'].values[:, np.newaxis]
|
|
|
178 |
|
179 |
return closest_user_embedding
|
180 |
|
181 |
+
|
182 |
+
def drop_non_numerical_columns(df):
|
183 |
+
non_numerical_columns = df.select_dtypes(exclude=[float, int]).columns
|
184 |
+
return df.drop(columns=non_numerical_columns, inplace=False)
|
185 |
+
|
186 |
+
def output_list(input_dict, movies_df = movie_embeds, tree = btree, user_embeddings = user_embeds, movies = final_movies):
|
187 |
+
movie_ratings = {}
|
188 |
+
for movie_title, rating in input_dict:
|
189 |
+
index = movies.index[movies['title'] == True].tolist()[0]
|
190 |
+
movie_ratings[index] = rating
|
191 |
user_embed = create_user_embedding(movie_ratings, movie_embeds)
|
192 |
# Call the find_closest_user function with the pre-built BallTree
|
193 |
closest_user_embed = find_closest_user(user_embed, tree, user_embeds)
|