How to use the cornac.data.Dataset.from_uir function in cornac

To help you get started, we’ve selected a few cornac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_matrix(self):
        from scipy.sparse import csr_matrix, csc_matrix, dok_matrix

        train_set = Dataset.from_uir(self.triplet_data)

        self.assertTrue(isinstance(train_set.matrix, csr_matrix))
        self.assertEqual(train_set.csr_matrix[0, 0], 4)
        self.assertTrue(train_set.csr_matrix.has_sorted_indices)

        self.assertTrue(isinstance(train_set.csc_matrix, csc_matrix))
        self.assertEqual(train_set.csc_matrix[4, 4], 3)

        self.assertTrue(isinstance(train_set.dok_matrix, dok_matrix))
        self.assertEqual(train_set.dok_matrix[7, 7], 5)
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_uir_iter(self):
        train_set = Dataset.from_uir(self.triplet_data)

        users = [batch_users for batch_users, _, _ in train_set.uir_iter()]
        self.assertSequenceEqual(users, range(10))

        items = [batch_items for _, batch_items, _ in train_set.uir_iter()]
        self.assertSequenceEqual(items, range(10))

        ratings = [batch_ratings for _, _, batch_ratings in train_set.uir_iter()]
        self.assertListEqual(ratings, [4, 4, 4, 4, 3, 4, 4, 5, 3, 4])

        ratings = [batch_ratings for _, _,
                   batch_ratings in train_set.uir_iter(binary=True)]
        self.assertListEqual(ratings, [1] * 10)

        ratings = [batch_ratings for _, _,
                   batch_ratings in train_set.uir_iter(batch_size=5, num_zeros=1)]
github PreferredAI / cornac / tests / cornac / eval_methods / test_base_method.py View on Github external
def test_testset_none(self):
        bm = BaseMethod(None, verbose=True)
        bm.train_set = Dataset.from_uir(data=Reader().read('./tests/data.txt'))
        try:
            bm.evaluate(None, {}, False)
        except ValueError:
            assert True
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_item_iter(self):
        train_set = Dataset.from_uir(self.triplet_data)

        npt.assert_array_equal(np.arange(10).reshape(10, 1),
                               [i for i in train_set.item_iter()])
        self.assertRaises(AssertionError, npt.assert_array_equal,
                          np.arange(10).reshape(10, 1),
                          [i for i in train_set.item_iter(shuffle=True)])
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_chrono_item_data(self):
        zero_data = []
        for idx in range(len(self.triplet_data)):
            u = self.triplet_data[idx][0]
            i = self.triplet_data[-1-idx][1]
            zero_data.append((u, i, 1., 0))
        train_set = Dataset.from_uirt(self.uirt_data + zero_data)

        self.assertEqual(len(train_set.chrono_item_data), 10)
        self.assertListEqual(train_set.chrono_item_data[0][1], [1., 4.])
        self.assertListEqual(train_set.chrono_item_data[0][2], [0, 882606572])
        
        try:
            Dataset.from_uir(self.triplet_data).chrono_item_data
        except ValueError:
            assert True
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_uir_tuple(self):
        train_set = Dataset.from_uir(self.triplet_data)

        self.assertEqual(len(train_set.uir_tuple), 3)
        self.assertEqual(len(train_set.uir_tuple[0]), 10)
        self.assertEqual(train_set.num_batches(batch_size=5), 2)
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_uij_iter(self):
        train_set = Dataset.from_uir(self.triplet_data, seed=123)

        users = [batch_users for batch_users, _, _ in train_set.uij_iter()]
        self.assertSequenceEqual(users, range(10))

        pos_items = [batch_pos_items for _, batch_pos_items, _ in train_set.uij_iter()]
        self.assertSequenceEqual(pos_items, range(10))

        neg_items = [batch_neg_items for _, _, batch_neg_items in train_set.uij_iter()]
        self.assertRaises(AssertionError, self.assertSequenceEqual,
                          neg_items, range(10))

        neg_items = [batch_neg_items for _, _,
                     batch_neg_items in train_set.uij_iter(neg_sampling='popularity')]
        self.assertRaises(AssertionError, self.assertSequenceEqual,
                          neg_items, range(10))
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_user_data(self):
        train_set = Dataset.from_uir(self.triplet_data)

        self.assertEqual(len(train_set.user_data), 10)
        self.assertListEqual(train_set.user_data[0][0], [0])
        self.assertListEqual(train_set.user_data[0][1], [4.0])
github PreferredAI / cornac / tests / cornac / data / test_dataset.py View on Github external
def test_chrono_user_data(self):
        zero_data = []
        for idx in range(len(self.triplet_data)):
            u = self.triplet_data[idx][0]
            i = self.triplet_data[-1-idx][1]
            zero_data.append((u, i, 1., 0))
        train_set = Dataset.from_uirt(self.uirt_data + zero_data)

        self.assertEqual(len(train_set.chrono_user_data), 10)
        self.assertListEqual(train_set.chrono_user_data[0][1], [1., 4.])
        self.assertListEqual(train_set.chrono_user_data[0][2], [0, 882606572])

        try:
            Dataset.from_uir(self.triplet_data).chrono_user_data
        except ValueError:
            assert True