Ejemplo n.º 1
0
def run_algorithm(data, parameters):
    if MODE == "SUBMIT":
        recommender = GDannunzioEnsemble(data["URM_complete"], data["URM_test"], icm=data["ICM"], parameters=parameters)
    else:
        recommender = GDannunzioEnsemble(data["URM_train"], data["URM_test"], icm=data["ICM"], parameters=parameters)
    recommender.fit()
    target = pd.read_csv('../data/target_playlists.csv', index_col=False)
    target  = target['playlist_id']
    recommended = recommender.recommend_batch(user_list=target, combiner=linearCombiner())
    playlists = recommended[:, 0]
    recommended = np.delete(recommended, 0, 1)
    i = 0
    res_fin = []
    for j in recommended:
        res = ''
        for k in range(0, len(j)):
            res = res + '{0} '.format(j[k])
        res_fin.append(res)
        i = i + 1
    d = {'playlist_id': playlists, 'track_ids': res_fin}
    df = pd.DataFrame(data=d, index=None)
    distrib_data = recommender.get_component_data()
    del recommender
    gc.collect()
    return [recommended, df, distrib_data]
Ejemplo n.º 2
0
    def recommend(self, user_id, combiner, at=10):
        user_profile = self.train[user_id, :]

        bm_list = self.bm_recommender.recommend(user_id, linearCombiner(), at=40)
        item_bpr_r = preprocessing.normalize(user_profile.dot(self.item_bpr_w).toarray(), norm='l2').ravel()

        bpr_scores = [
            [item_bpr_r, self.ensemble_weights["ITEM_BPR"], "ITEM_BPR"]
        ]

        for r in bpr_scores:
            self.filter_seen(user_id, r[0])

        bpr_list = (linearCombiner()).combine(bpr_scores, at=40)
        lists = [
            [bm_list],
            [bpr_list]
            ]

        return (ProbabilisticCombiner()).combine(scores=lists, alpha=self.ensemble_weights["ALPHA"], at=at)