def recommendPosts(dataModel): model = MatrixPreferenceDataModel(dataModel) print 'User ID`s: ' print model.user_ids() ## print 'Item ID`s: ' ## print model.item_ids() userID= input('Please enter a userID: ') print 'Loading recommended posts...' similarity = UserSimilarity(model, pearson_correlation) recommender = UserBasedRecommender(model, similarity, with_preference=True) return recommender.recommend(userID)
def build_and_save_recommendations(self, user_items_preference_map): model = MatrixPreferenceDataModel(user_items_preference_map) #item_similarity = ItemSimilarity(model, loglikehood_coefficient) user_similarity = UserSimilarity(model, loglikehood_coefficient) item_recommendations = ItemBasedColaborativeFiltering(user_items_preference_map).build_recommendations() user_recommender = UserBasedRecommender(model, user_similarity, with_preference=True) for item, item_weight_map in item_recommendations.iteritems(): ItemRecommendations.save_recommendations_for_item(item, item_weight_map.iteritems()) user_work_queue = multiprocessing.Queue() for user_id in model.user_ids().tolist(): user_work_queue.put(user_id) ParallelWork(UserRecommenderWorker, (user_work_queue, user_recommender)).begin()