forked from git-ankit/MovieRecommender
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/adipai/PopcornPicks
- Loading branch information
Showing
2 changed files
with
30 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
import pandas as pd | ||
import warnings | ||
import os | ||
|
||
app_dir = os.path.dirname(os.path.abspath(__file__)) | ||
code_dir = os.path.dirname(app_dir) | ||
project_dir = os.path.dirname(code_dir) | ||
|
||
#warnings.filterwarnings("ignore") | ||
|
||
|
||
def recommendForNewUser(user_rating): | ||
ratings = pd.read_csv(project_dir + "/data/ratings.csv") | ||
movies = pd.read_csv(project_dir + "/data/movies.csv") | ||
def recommend_for_new_user(user_rating): | ||
ratings = pd.read_csv(os.path.join(project_dir, "data", "ratings.csv")) | ||
movies = pd.read_csv(os.path.join(project_dir, "data", "movies.csv")) | ||
user = pd.DataFrame(user_rating) | ||
userMovieID = movies[movies["title"].isin(user["title"])] | ||
userRatings = pd.merge(userMovieID, user) | ||
user_movie_id = movies[movies["title"].isin(user["title"])] | ||
user_ratings = pd.merge(user_movie_id, user) | ||
|
||
moviesGenreFilled = movies.copy(deep=True) | ||
copyOfMovies = movies.copy(deep=True) | ||
for index, row in copyOfMovies.iterrows(): | ||
copyOfMovies.at[index, "genres"] = row["genres"].split("|") | ||
for index, row in copyOfMovies.iterrows(): | ||
movies_genre_filled = movies.copy(deep=True) | ||
copy_of_movies = movies.copy(deep=True) | ||
|
||
for index, row in copy_of_movies.iterrows(): | ||
copy_of_movies.at[index, "genres"] = row["genres"].split("|") | ||
|
||
for index, row in copy_of_movies.iterrows(): | ||
for genre in row["genres"]: | ||
moviesGenreFilled.at[index, genre] = 1 | ||
moviesGenreFilled = moviesGenreFilled.fillna(0) | ||
movies_genre_filled.at[index, genre] = 1 | ||
|
||
movies_genre_filled = movies_genre_filled.fillna(0) | ||
|
||
userGenre = moviesGenreFilled[moviesGenreFilled.movieId.isin(userRatings.movieId)] | ||
userGenre.drop(["movieId", "title", "genres"], axis=1, inplace=True) | ||
userProfile = userGenre.T.dot(userRatings.rating.to_numpy()) | ||
moviesGenreFilled.set_index(moviesGenreFilled.movieId) | ||
moviesGenreFilled.drop(["movieId", "title", "genres"], axis=1, inplace=True) | ||
user_genre = movies_genre_filled[movies_genre_filled.movieId.isin(user_ratings.movieId)] | ||
user_genre.drop(["movieId", "title", "genres"], axis=1, inplace=True) | ||
user_profile = user_genre.T.dot(user_ratings.rating.to_numpy()) | ||
|
||
movies_genre_filled.set_index(movies_genre_filled.movieId) | ||
movies_genre_filled.drop(["movieId", "title", "genres"], axis=1, inplace=True) | ||
|
||
recommendations = (moviesGenreFilled.dot(userProfile)) / userProfile.sum() | ||
joinMoviesAndRecommendations = movies.copy(deep=True) | ||
joinMoviesAndRecommendations["recommended"] = recommendations | ||
joinMoviesAndRecommendations.sort_values( | ||
recommendations = (movies_genre_filled.dot(user_profile)) / user_profile.sum() | ||
|
||
join_movies_and_recommendations = movies.copy(deep=True) | ||
join_movies_and_recommendations["recommended"] = recommendations | ||
join_movies_and_recommendations.sort_values( | ||
by="recommended", ascending=False, inplace=True | ||
) | ||
return [x for x in joinMoviesAndRecommendations["title"]][:201] | ||
|
||
return list(join_movies_and_recommendations["title"][:201]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters