Last active
November 5, 2018 06:20
-
-
Save KevinLiao159/41df1538e21cd8cfbbbe768fc90f0265 to your computer and use it in GitHub Desktop.
The "make_recommendations" method from my KNN recommender
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
def make_recommendations(self, fav_movie, n_recommendations): | |
""" | |
make top n movie recommendations | |
Parameters | |
---------- | |
fav_movie: str, name of user input movie | |
n_recommendations: int, top n recommendations | |
""" | |
# get data | |
movie_user_mat_sparse, hashmap = self._prep_data() | |
# get recommendations | |
raw_recommends = self._inference( | |
self.model, movie_user_mat_sparse, hashmap, | |
fav_movie, n_recommendations) | |
# print results | |
reverse_hashmap = {v: k for k, v in hashmap.items()} | |
print('Recommendations for {}:'.format(fav_movie)) | |
for i, (idx, dist) in enumerate(raw_recommends): | |
print('{0}: {1}, with distance ' | |
'of {2}'.format(i+1, reverse_hashmap[idx], dist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For entire source code of KNN recommender, please visit this page