-
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.
- Loading branch information
1 parent
7219a4f
commit 60a9c35
Showing
1 changed file
with
38 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pickle | ||
|
||
import numpy as np | ||
|
||
|
||
class RecommendationEngine: | ||
def __init__(self, model_file): | ||
with open(model_file, "rb") as f: | ||
self.model = pickle.load(f) | ||
|
||
def titles_to_ids(self, titles): | ||
pass | ||
|
||
def ids_to_titles(self, ids): | ||
pass | ||
|
||
def get_recommendations(self, user_id, movie_ids): | ||
scores = self.model.predict( | ||
user_id, | ||
movie_ids, | ||
) | ||
return np.argsort(-scores) | ||
|
||
def get_data(self, user_id): | ||
print("Enter liked movies: ") | ||
return input().split(",") | ||
|
||
def display_recommendations(self, recommendations): | ||
movie_titles = self.ids_to_titles(recommendations) | ||
print("Recommended movies: ") | ||
for title in movie_titles: | ||
print(title) | ||
|
||
def recommend(self, user_id=1): | ||
liked_movies = self.get_data(user_id) | ||
liked_movies_ids = self.titles_to_ids(liked_movies) | ||
recommendations = self.get_recommendations(user_id, liked_movies_ids) | ||
self.display_recommendations(recommendations) |