def __init__(self, urm, urm_t, icm, icm2, enable_dict, urm_test):
        self.urm = urm
        self.n_users, self.n_items = urm.getCSR().shape
        self.setEnables(enable_dict )

        self.item_item = IIHybridRecommender(urm, icm, icm2)
        self.item_item.fit(item_weight=0.4, cbf1_weight=0.25, cbf2_weight=0.1)

        self.user = CollaborativeFiltering()
        self.user.fit(urm_t, k=100, h=0, mode='user')

        if self.enableSVD:
            self.svd = SVDRecommender(urm, nf=385)

        if self.enableP3A:
            self.p3a = P3alpha(urm.getCSR())
            self.p3a.fit(topK=80, alpha=1, min_rating=0, implicit=True, normalize_similarity=True)

        if self.enableSLIM:
            choice = 2
            logFile = open("SLIM_BPR_Cython.txt", "a")

            self.slim = SLIM_BPR_Cython(urm.getCSR(), recompile_cython=False, positive_threshold=0,
                                        URM_validation=urm_test.getCSR(), final_model_sparse_weights=True,
                                        train_with_sparse_weights=False)

            self.slim.fit(epochs=100, validation_every_n=1, logFile=logFile, batch_size=5, topK=200,
                          sgd_mode="adagrad", learning_rate=0.075)

        if self.enableLFM:
            # LightFM
            print("starting USER CF")
            self.lfm = LightFMRecommender()
            self.lfm.fit(urm, epochs=100)
            print("USER CF finished")
    def __init__(self, urm, urm_t, icm, icm2, enable_dict, urm_test=None):
        self.urm = urm
        self.setEnables(enable_dict)

        if self.enableSVD:
            self.svd = SVDRecommender(urm, nf=385)

        if self.enableSLIM:
            logFile = open("SLIM_BPR_Cython.txt", "a")

            self.slim = SLIM_BPR_Cython(urm.getCSR(),
                                        recompile_cython=False,
                                        positive_threshold=0,
                                        URM_validation=urm_test.getCSR(),
                                        final_model_sparse_weights=True,
                                        train_with_sparse_weights=False)

            self.slim.fit(epochs=100,
                          validation_every_n=1,
                          logFile=logFile,
                          batch_size=5,
                          topK=200,
                          sgd_mode="adagrad",
                          learning_rate=0.075)

            self.slim_sim = self.slim.get_similarity()

        if self.enableLFM:
            # LightFM
            print("starting USER CF")
            self.lfm = LightFMRecommender()
            self.lfm.fit(urm, epochs=100)
            print("USER CF finished")

        # User based
        print("starting USER CF")
        self.cbu = CollaborativeFiltering()
        self.cbu.fit(urm_t, k=100, h=8, mode='user')
        print("USER CF finished")

        # Item based
        print("starting ITEM CF")
        self.cbi = CollaborativeFiltering()
        self.cbi.fit(urm, k=125, h=10, mode='item')
        print("ITEM CF finished")

        # Content based artist
        print("starting CBF")
        self.cbf = ContentBasedFiltering(icm, urm, k=25, shrinkage=100)
        self.cbf.fit()
        print("CBF finished")

        if self.enableCBF2:
            print("starting CBF2")
            self.cbf2 = ContentBasedFiltering(icm2, urm, k=25, shrinkage=100)
            self.cbf2.fit()
            print("CBF2 finished")
    def __init__(self, urm, urm_t, icm, icm2, enable_dict, urm_test=None):
        self.urm = urm
        self.setEnables(enable_dict)

        if self.enableRP3B:
            self.rp3b = RP3betaRecommender(urm.getCSR())
            self.rp3b.fit(topK=100,
                          alpha=0.7,
                          beta=0.3,
                          normalize_similarity=True,
                          implicit=True)

        if self.enableSLIM:
            choice = 2
            logFile = open("SLIM_BPR_Cython.txt", "a")

            self.slim = SLIM_BPR_Cython(urm.getCSR(),
                                        recompile_cython=False,
                                        positive_threshold=0,
                                        URM_validation=urm_test.getCSR(),
                                        final_model_sparse_weights=True,
                                        train_with_sparse_weights=False)

            self.slim.fit(epochs=100,
                          validation_every_n=1,
                          logFile=logFile,
                          batch_size=5,
                          topK=200,
                          sgd_mode="adagrad",
                          learning_rate=0.075)

            self.slim_sim = self.slim.get_similarity()

        if self.enableP3A:
            self.p3a = P3alpha(urm.getCSR())
            self.p3a.fit(topK=80,
                         alpha=1,
                         min_rating=0,
                         implicit=True,
                         normalize_similarity=True)

        # if self.enableCBF2:
        #     print("starting CBF2")
        #     self.cbf2 = ContentBasedFiltering(icm2, urm, k=25, shrinkage=0)
        #     self.cbf2.fit()
        #     print("CBF2 finished")

        if self.enableLFM:
            # LightFM
            print("starting USER CF")
            self.lfm = LightFMRecommender()
            self.lfm.fit(urm, epochs=100)
            print("USER CF finished")

        if self.enableSVD:
            self.svd = PureSVDRecommender(urm.getCSR())
            self.svd.fit(num_factors=225)
            print("USER CF finished")

        # User based
        print("starting USER CF")
        self.cbu = CollaborativeFiltering()
        self.cbu.fit(urm_t, k=100, h=0, mode='user')
        print("USER CF finished")

        self.item_item = IIHybridRecommender(urm, icm, icm2)
        self.item_item.fit(item_weight=0.4, cbf1_weight=0.25, cbf2_weight=0.1)
Exemple #4
0
    rp3b = RP3betaRecommender(urm.getCSR())
    rp3b.fit(**cf_parameters)

    if submission:
        recommended_items = rp3b.m_recommend(targetList, nRec=10)
        generate_output(targetList, recommended_items)
    else:
        cumulative_precision, cumulative_recall, cumulative_MAP = evaluate_algorithm(
            urm_test, rp3b)
        print(
            "Recommender, performance is: Precision = {:.4f}, Recall = {:.4f}, MAP = {:.6f}"
            .format(cumulative_precision, cumulative_recall, cumulative_MAP))

elif htype == "lfm":
    lfm = LightFMRecommender()
    lfm.fit(urm.getCSR(), epochs=100)

    if submission:
        recommended_items = lfm.m_recommend(targetList, nRec=10)
        generate_output(targetList, recommended_items)
    else:
        cumulative_precision, cumulative_recall, cumulative_MAP = evaluate_algorithm(
            urm_test, lfm)
        print(
            "Recommender, performance is: Precision = {:.4f}, Recall = {:.4f}, MAP = {:.6f}"
            .format(cumulative_precision, cumulative_recall, cumulative_MAP))

elif htype == "xgb":
    enable_dict = {
        'enableSVD': False,