예제 #1
0
    def __init__(self, URM_train, Recommender):
        super(ColdUsersTopPopRecommender, self).__init__(URM_train)

        self.URM_train = check_matrix(URM_train.copy(), "csr")

        self.Recommender = Recommender

        self.topPop = TopPop(URM_train)
예제 #2
0
    def __init__(self, urm_train):
        super(HybridZeroRecommender, self).__init__(urm_train)

        urm_train = check_matrix(urm_train.copy(), 'csr')

        data = DataManager()

        ucm_age, ucm_region, ucm_all = data.get_ucm()

        recommender_1 = TopPop(urm_train)
        recommender_1.fit()
        #
        recommender_2 = UserKNNCBFRecommender(urm_train, ucm_all)
        recommender_2.fit(shrink=500, topK=1600, similarity='tversky')

        self.recommender_1 = recommender_1
        self.recommender_2 = recommender_2
예제 #3
0
 def __init__(self,
              URM_train,
              ICM_train,
              submission=False,
              verbose=True,
              seed=1205):
     super(ColdUserEmbedding001, self).__init__(URM_train, verbose=verbose)
     self.__warm_recommender = LinearHybrid003(URM_train,
                                               ICM_train,
                                               submission=submission,
                                               verbose=verbose,
                                               seed=seed)
     self.__warm_params = {
         'alpha': 0.4357334022190923,
         'l1_ratio': 0.7855628829453338
     }
     self.__cold_recommender = TopPop(URM_train)
     self.__cold_params = {}
 def __init__(self,
              URM_train,
              ICM_train,
              submission=False,
              verbose=True,
              seed=1205):
     super(ColdUserEmbedding002, self).__init__(URM_train, verbose=verbose)
     self.__warm_recommender = LinearHybrid005(URM_train,
                                               ICM_train,
                                               submission=submission,
                                               verbose=verbose,
                                               seed=seed)
     self.__warm_params = {
         'alpha': 0.3553383791480798,
         'l1_ratio': 0.000435281815357902
     }
     self.__cold_recommender = TopPop(URM_train)
     self.__cold_params = {}
예제 #5
0
 def __init__(self, data: DataObject):
     super(Hybrid100AlphaRecommender, self).__init__(data.urm_train)
     self.data = data
     self.rec1 = UserKNNCBFRecommender(data.ucm_all, data.urm_train)
     self.rec2 = TopPop(data.urm_train)
     self.rec1.fit(topK=5000,
                   shrink=5,
                   feature_weighting="TF-IDF",
                   similarity="euclidean")
     self.rec2.fit()
     cold = data.ids_cold_user
     train_cold = data.urm_train_users_by_type[0][1]
     if train_cold.shape[0] > 0:
         target_users = np.append(cold, train_cold)
     else:
         target_users = cold
     self.target_users = target_users
     self.hybrid_rec = Hybrid1CXAlphaRecommender(
         data,
         recommenders=[self.rec1, self.rec2],
         recommended_users=target_users,
         max_cutoff=20)
예제 #6
0
    def __init__(self, URM_train, ICM_all, verbose=True):
        super(UserWiseHybrid001, self).__init__(URM_train, verbose=verbose)
        self.URM_train = URM_train
        self.ICM_all = ICM_all

        # range and recommender definition ---> element structure: ( (start, end), recommender, fit_args* )
        self.__recommender_segmentation = [
            ((0, 1), TopPop(URM_train), {}),
            ((1, 25), P3alphaRecommender(URM_train),
             {'topK': 729, 'alpha': 0.4104229220476686, 'normalize_similarity': False}),
            ((25, 50), RP3betaRecommender(URM_train),
             {'topK': 939, 'alpha': 0.6073516078011799, 'beta': 0.002238854541773972, 'normalize_similarity': False}),
            ((50, 100), UserKNNCFRecommender(URM_train),
             {'topK': 90, 'shrink': 77, 'similarity': 'cosine', 'normalize': True}),
            ((100, 200), RP3betaRecommender(URM_train),
             {'topK': 1000, 'alpha': 0.32110178834628456, 'beta': 0.0, 'normalize_similarity': True}),
            ((200, -1), SLIM_BPR_Cython(URM_train),
             {'topK': 120, 'epochs': 20, 'symmetric': True, 'sgd_mode': 'adam', 'lambda_i': 0.01, 'lambda_j': 1e-05, 'learning_rate': 0.0001}),
        ]

        self.__loaded = {}
        for f_range, _, _ in self.__recommender_segmentation:
            self.__loaded[f_range] = False
예제 #7
0
URM_train, URM_validation, URM_test = dataSplitter.get_holdout_split()

ICM_dict = dataSplitter.get_loaded_ICM_dict()

# Now that we have the split, we can create the evaluators.
# The constructor of the evaluator allows you to specify the evaluation conditions (data, recommendation list length,
# excluding already seen items). Whenever you want to evaluate a model, use the evaluateRecommender function of the evaluator object
evaluator_validation = EvaluatorHoldout(URM_validation,
                                        cutoff_list=[5],
                                        exclude_seen=False)
evaluator_test = EvaluatorHoldout(URM_test,
                                  cutoff_list=[5, 10, 20],
                                  exclude_seen=False)

# We now fit and evaluate a non personalized algorithm
recommender = TopPop(URM_train)
recommender.fit()

results_dict, results_run_string = evaluator_validation.evaluateRecommender(
    recommender)
print("Result of TopPop is:\n" + results_run_string)

# We now fit and evaluate a personalized algorithm passing some hyperparameters to the fit functions
recommender = P3alphaRecommender(URM_train)
recommender.fit(topK=100, alpha=0.5)

results_dict, results_run_string = evaluator_validation.evaluateRecommender(
    recommender)
print("Result of P3alpha is:\n" + results_run_string)

# We now use a content-based algorithm and a hybrid content-collaborative algorithm
예제 #8
0
print("The MAP in one test is: ", MAP)

itemCF_recommender = ItemKNNCFRecommender(URM_all)
itemCF_recommender.fit(**itemCFParam)
slim_recommender = SLIM_BPR_Cython(URM_all, recompile_cython=False)
slim_recommender.fit(**slimParam)
p3_recommender = P3alphaRecommender(URM_all)
p3_recommender.fit(**p3Param)
recommender1 = SimilarityHybridRecommender(URM_all,
                                           itemCF_recommender.W_sparse,
                                           slim_recommender.W_sparse,
                                           p3_recommender.W_sparse)
recommender1.fit(topK=100, alpha1=alpha1, alpha2=alpha2, alpha3=alpha3)
recommender1.save_model("model/", "hybrid_item_slim_basic")

topPopRecommender = TopPop(URM_all)
topPopRecommender.fit()

results_test = test_save(recommender1, topPopRecommender, test_path,
                         warm_users)
create_csv(results_test, 'Cold_Item_SLIM_BPR_parameter_tuning')
print("finished")
print("The MAP in one test is: ", MAP)
print("The average best MAP is: ", average_map)
"""
mapLists = np.zeros((len(userCFParamList), len(slimParamList), len(p3ParamList)))
num_iteration = 2

for _ in range(num_iteration):
    for i, user_cf_param in enumerate(userCFParamList):
        for j, slim_param in enumerate(slimParamList):