Exemplo n.º 1
0
 def step_hybrid_seven(self,
                       weight1=0,
                       weight2=0,
                       weight3=0,
                       weight4=0,
                       weight5=0,
                       weight6=0,
                       weight7=0):
     start_time = time.time()
     UCM_all = self.helper.UCM_all
     ICM_all = self.helper.ICM_all
     self.recommender.fit(self.helper.URM_train,
                          ICM_all=ICM_all,
                          UCM_all=UCM_all,
                          weights=[
                              weight1, weight2, weight3, weight4, weight5,
                              weight6, weight7
                          ],
                          tuning=True)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 2
0
    def run(self, requires_ucm=False, requires_icm=False):
        self.functionality.get_URM()

        if requires_icm:
            self.functionality.get_ICM()

        if requires_ucm:
            self.functionality.get_UCM()

        self.functionality.get_target_users()
        self.fit_recommender(requires_icm, requires_ucm)
        if not self.evaluate:
            # Recommendations on target users are necessary only during file printing
            self.run_recommendations()
        if self.evaluate:
            evaluation.evaluate_algorithm(self.functionality.URM_test,
                                          self.recommender,
                                          at=10)
Exemplo n.º 3
0
 def step_PureSVD_randomSVD(self, n_components, n_iter):
     start_time = time.time()
     self.recommender.fit(self.helper.URM_train,
                          n_components=int(n_components),
                          n_iter=int(n_iter))
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 4
0
 def step_P3Alpha(self, weight1=0, weight2=0):
     start_time = time.time()
     self.recommender.fit(self.helper.URM_train,
                          topK=int(weight1),
                          alpha=weight2)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 5
0
 def step_FunkSVD(self, epoch, num_factors, learning_rate, user_reg,
                  item_reg):
     start_time = time.time()
     self.recommender = MatrixFactorization_FunkSVD_Cython(
         int(epoch), int(num_factors), learning_rate, user_reg, item_reg)
     self.recommender.fit(self.helper.URM_train)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 6
0
 def step_ALS(self, weight1=0, weight2=0, weight3=0):
     start_time = time.time()
     self.recommender = AlternatingLeastSquare(n_factors=int(weight1),
                                               regularization=weight2,
                                               iterations=int(weight3))
     self.recommender.fit(self.helper.URM_train)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 7
0
 def step_slim(self, weight1=0, weight2=0, weight3=0):
     start_time = time.time()
     self.recommender = SLIM_BPR_Cython(lambda_i=weight1,
                                        lambda_j=weight2,
                                        learning_rate=weight3)
     self.recommender.fit(self.helper.URM_train)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 8
0
 def step_RP3Beta(self, alpha=0, beta=0, min_rating=0, topK=0):
     start_time = time.time()
     self.recommender.fit(self.helper.URM_train,
                          alpha=alpha,
                          beta=beta,
                          min_rating=min_rating,
                          topK=int(topK))
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 9
0
 def step_User_CB(self, weight1=0, weight2=0):
     start_time = time.time()
     UCM_all = self.helper.UCM_all
     self.recommender.fit(self.helper.URM_train,
                          UCM_all,
                          knn=int(weight1),
                          shrink=int(weight2))
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 10
0
 def step_fallBack_Hybrid(self, weight1=0, weight2=0):
     start_time = time.time()
     UCM_all = self.helper.UCM_all
     ICM_all = self.helper.ICM_all
     self.recommender.fit(self.helper.URM_train,
                          ICM_all=ICM_all,
                          UCM_all=UCM_all,
                          weights_fallback=[int(weight1),
                                            int(weight2)],
                          tuning=True)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 11
0
 def step_weight(self, w1, w2):
     start_time = time.time()
     print("----------------------------------------")
     print("HybridCombination: " + self.name)
     print([w1, w2])
     print("----------------------------------------")
     list_UCM = [self.helper.UCM_age, self.helper.UCM_region]
     list_ICM = [
         self.helper.ICM, self.helper.ICM_price, self.helper.ICM_asset
     ]
     self.recommender.fit(self.helper.URM_train, [w1, w2],
                          list_ICM=list_ICM,
                          list_UCM=list_UCM,
                          tuning=False)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 12
0
 def step_TEST(self, t1, t2, t3, t4, t5):
     start_time = time.time()
     UCM_all = self.helper.UCM_all
     ICM_all = self.helper.ICM_all
     self.recommender = Hybrid_User_Wise("Hybrid User Wise",
                                         UserCBFKNNRecommender())
     self.recommender.fit(self.helper.URM_train,
                          ICM_all=ICM_all,
                          UCM_all=UCM_all,
                          thre1=t1,
                          thre2=t2,
                          thre3=t3,
                          thre4=t4,
                          thre5=t5,
                          tuning=True)
     cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                self.recommender,
                                                at=10)
     elapsed_time = time.time() - start_time
     print("----------------" + str(elapsed_time) + "----------------")
     return cumulative
Exemplo n.º 13
0
    def step_all(self,
                 H0_ICF_sh=0,
                 H0_ICF_tK=0,
                 H1_UCF_sh=0,
                 H1_UCF_tK=0,
                 H2_ICB_sh=0,
                 H2_ICB_tK=0,
                 H3_UCB_sh=0,
                 H3_UCB_tK=0,
                 H4_El_tK=0,
                 H5_RP3_a=0,
                 H5_RP3_b=0,
                 H5_RP3_tK=0,
                 H6_SL_bs=0,
                 H6_SL_ep=0,
                 H6_SL_l_i=0,
                 H6_SL_l_j=0,
                 H6_SL_l_r=0,
                 H6_SL_tK=0,
                 H7_ALS_i=0,
                 H7_ALS_nf=0,
                 H7_ALS_re=0,
                 weight1=0,
                 weight2=0,
                 weight3=0,
                 weight4=0,
                 weight5=0,
                 weight6=0,
                 weight7=0):

        start_time = time.time()
        UCM_all = self.helper.UCM_all
        ICM_all = self.helper.ICM_all

        ItemCF = ItemKNNCFRecommender()
        UserCF = UserKNNCFRecommender()
        ItemCB = ItemCBFKNNRecommender()
        UserCB = UserCBFKNNRecommender()
        ElasticNet = SLIMElasticNetRecommender()
        RP3Beta = RP3BetaRecommender()
        Slim = SLIM_BPR_Cython(batch_size=int(H6_SL_bs),
                               epochs=int(H6_SL_ep),
                               lambda_i=H6_SL_l_i,
                               lambda_j=H6_SL_l_j,
                               learning_rate=H6_SL_l_r,
                               topK=int(H6_SL_tK))
        ALS = AlternatingLeastSquare(iterations=int(H7_ALS_i),
                                     n_factors=int(H7_ALS_nf),
                                     regularization=H7_ALS_re)

        ItemCF.fit(self.helper.URM_train, knn=int(H0_ICF_tK), shrink=H0_ICF_sh)
        UserCF.fit(self.helper.URM_train, knn=int(H1_UCF_tK), shrink=H1_UCF_sh)
        ItemCB.fit(self.helper.URM_train,
                   ICM_all,
                   knn=int(H2_ICB_tK),
                   shrink=H2_ICB_sh)
        UserCB.fit(self.helper.URM_train,
                   UCM_all,
                   knn=int(H3_UCB_tK),
                   shrink=H3_UCB_sh)
        ElasticNet.fit(self.helper.URM_train, topK=int(H4_El_tK))
        RP3Beta.fit(self.helper.URM_train,
                    alpha=H5_RP3_a,
                    beta=H5_RP3_b,
                    topK=int(H5_RP3_tK))
        Slim.fit(self.helper.URM_train)
        ALS.fit(self.helper.URM_train)

        self.recommender = Hybrid_Achille_Tuning("Hybrid_Achille_Tuning_All",
                                                 UserCB)
        self.recommender.fit(self.helper.URM_train,
                             ICM_all=ICM_all,
                             UCM_all=UCM_all,
                             weights=[
                                 weight1, weight2, weight3, weight4, weight5,
                                 weight6, weight7
                             ],
                             ItemCF=ItemCF,
                             UserCF=UserCF,
                             ItemCB=ItemCB,
                             ElasticNet=ElasticNet,
                             RP3=RP3Beta,
                             Slim=Slim,
                             ALS=ALS)
        cumulative = evaluation.evaluate_algorithm(self.helper.URM_test,
                                                   self.recommender,
                                                   at=10)
        elapsed_time = time.time() - start_time
        print("----------------" + str(elapsed_time) + "----------------")
        return cumulative