Exemplo n.º 1
0
 def get_mf(self):
     MatrixFactorization(
         train_file=self.train_file,
         test_file=self.test_file,
         output_file=self.output_file,
         factors=int(self.factors),
         learn_rate=self.learn_rate,
         delta=self.delta,
         sep=self.sep,
         output_sep=self.output_sep).compute(verbose_evaluation=False)
Exemplo n.º 2
0
    def run_recommenders(self, r):
        """
        1: Item KNN
        2: User KNN
        3: Matrix Factorization
        4: SVD++
        """

        flag = True

        if not self.unlabeled_data[r]:
            flag = False

            return [], flag

        else:
            if r == 1:
                rec = ItemKNN(self.labeled_files[r],
                              self.unlabeled_files[r],
                              as_similar_first=True)
                rec.read_files()
                rec.init_model()
                rec.train_baselines()
                rec.predict()
                self.recommenders_predictions.setdefault(r, rec.predictions)
            elif r == 2:
                rec = UserKNN(self.labeled_files[r], self.unlabeled_files[r])
                rec.read_files()
                rec.init_model()
                rec.train_baselines()
                rec.predict()
                self.recommenders_predictions.setdefault(r, rec.predictions)
            elif r == 3:
                rec = MatrixFactorization(self.labeled_files[r],
                                          self.unlabeled_files[r],
                                          random_seed=1,
                                          baseline=True)
                rec.read_files()
                rec.init_model()
                rec.fit()
                rec.predict()
                self.recommenders_predictions.setdefault(r, rec.predictions)
            elif r == 4:
                rec = SVDPlusPlus(self.labeled_files[r],
                                  self.unlabeled_files[r],
                                  random_seed=1)
                rec.read_files()
                rec.fit()
                rec.predict()
                self.recommenders_predictions.setdefault(r, rec.predictions)

            else:
                raise NameError('Invalid Recommender!')

            return rec.predictions, flag
Exemplo n.º 3
0
"""

from caserec.recommenders.rating_prediction.svdplusplus import SVDPlusPlus
from caserec.recommenders.rating_prediction.matrixfactorization import MatrixFactorization
from caserec.utils.cross_validation import CrossValidation

db = 'C:/Users/user/OneDrive/ml-100k/u.data'
folds_path = 'C:/Users/user/OneDrive/ml-100k/'

metadata_item = 'C:/Users/user/OneDrive/ml-100k/db_item_subject.dat'
sm_item = 'C:/Users/user/OneDrive/ml-100k/sim_item.dat'
metadata_user = '******'
sm_user = '******'

tr = 'C:/Users/user/OneDrive/ml-100k/folds/0/train.dat'
te = 'C:/Users/user/OneDrive/ml-100k/folds/0/test.dat'
"""

    UserKNN

"""

# Cross Validation
recommender = MatrixFactorization()

# CrossValidation(input_file=db, recommender=recommender, dir_folds=folds_path, header=1, k_folds=5).compute()

# # Simple
MatrixFactorization(tr, te).compute()
SVDPlusPlus(tr, te).compute()
from caserec.utils.cross_validation import CrossValidation

db = '../../datasets/ml-100k/u.data'
folds_path = '../../datasets/ml-100k/'

metadata_item = '../../datasets/ml-100k/db_item_subject.dat'
sm_item = '../../datasets/ml-100k/sim_item.dat'
metadata_user = '******'
sm_user = '******'

tr = '../../datasets/ml-100k/folds/0/train.dat'
te = '../../datasets/ml-100k/folds/0/test.dat'
"""

    UserKNN

"""

# Cross Validation
recommender = MatrixFactorization()

CrossValidation(input_file=db,
                recommender=recommender,
                dir_folds=folds_path,
                header=1,
                k_folds=5).compute()

# # Simple
# MatrixFactorization(tr, te).compute()
# SVDPlusPlus(tr, te).compute()
Exemplo n.º 5
0
    UserKNN

"""

# Cross Validation
# recommender = MatrixFactorization()

# CrossValidation(input_file=db, recommender=recommender, dir_folds=folds_path, header=1, k_folds=5).compute()

# # Simple
# MatrixFactorization(tr, te).compute()
# SVDPlusPlus(tr, te).compute()

train = "C:/dev/train.dat"
test = "C:/dev/test.dat"
metadata = "C:/dev/item_subject.dat"
# GSVDPlusPlus(train, test, metadata_file=metadata).compute()
similarity = "C:/dev/vsm.dat"

MatrixFactorization(train, test, random_seed=0, epochs=30,
                    stop_criteria=0.009).compute()
ItemMSMF(train,
         test,
         similarity_file=similarity,
         neighbors=20,
         random_seed=0,
         baseline=True,
         epochs=30,
         stop_criteria=0.009).compute()