Skip to content

Instantly share code, notes, and snippets.

@KevinLiao159
Created November 11, 2018 01:37
Show Gist options
  • Save KevinLiao159/c55aab169a4439f52c6345d591e57ebc to your computer and use it in GitHub Desktop.
Save KevinLiao159/c55aab169a4439f52c6345d591e57ebc to your computer and use it in GitHub Desktop.
The "make_recommendations" method from my ALS recommender
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))
@KevinLiao159
Copy link
Author

KevinLiao159 commented Nov 11, 2018

For entire source code of ALS recommender, please visit this page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment