def test_case_1(self):
        pipeline = Pipeline([('sparse', SparseMatrixCreator()),
                             ('fit', NMFRecommender(n_components=2))])

        preprecessed_data_dict = preprocessing(self.data_dict, True, 50, 50)

        tds = TrainTestSplitter(preprecessed_data_dict, 10, 0.2)

        train, test = next(tds.__iter__())

        pipeline.fit(train)

        y_pred = pipeline._final_estimator.predict(test)

        y_true = test['ratings']['Book-Rating'].values

        print(rmse(y_true, y_pred))
Ejemplo n.º 2
0
 def test_case_2(self):
     algo = SVDpp()
     reader = Reader(rating_scale=(1, 10))
     preprocessed_data_dict = preprocessing(self.data_dict, False, 100, 100)
     preprocessed_data_dict['ratings'] = preprocessed_data_dict[
         'ratings'].rename(
             {
                 'User-ID': 'userID',
                 'ISBN': 'itemID',
                 'Book-Rating': 'rating'
             },
             axis='columns')
     data = Dataset.load_from_df(
         preprocessed_data_dict['ratings'][['userID', 'itemID', 'rating']],
         reader)
     my_cross_validation(algo,
                         data,
                         k=5,
                         threshold=7,
                         n_splits=5,
                         verbose=True)