Created
          November 11, 2018 01:37 
        
      - 
      
- 
        Save KevinLiao159/c55aab169a4439f52c6345d591e57ebc to your computer and use it in GitHub Desktop. 
    The "make_recommendations" method from my ALS recommender
  
        
  
    
      This file contains hidden or 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 ALS recommender, please visit this page