How to use cornac - 10 common examples

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 / experiment / test_experiment.py View on Github external
def test_with_ratio_split(self):
        Experiment(eval_method=RatioSplit(self.data + [(self.data[0][0], self.data[1][1], 5.0)],
                                          exclude_unknowns=True, seed=123, verbose=True),
                   models=[PMF(1, 0)],
                   metrics=[MAE(), RMSE()],
                   verbose=True).run()

        try:
            Experiment(None, None, None)
        except ValueError:
            assert True

        try:
            Experiment(None, [PMF(1, 0)], None)
        except ValueError:
            assert True
github PreferredAI / cornac / tests / cornac / data / test_reader.py View on Github external
def test_filter(self):
        reader = Reader(bin_threshold=4.0)
        data = reader.read(self.data_file)
        self.assertEqual(len(data), 8)
        self.assertListEqual([x[2] for x in data], [1] * len(data))

        reader = Reader(min_user_freq=2)
        self.assertEqual(len(reader.read(self.data_file)), 0)

        reader = Reader(min_item_freq=2)
        self.assertEqual(len(reader.read(self.data_file)), 0)

        reader = Reader(user_set=['76'], item_set=['93'])
        self.assertEqual(len(reader.read(self.data_file)), 1)

        reader = Reader(user_set=['76', '768'])
        self.assertEqual(len(reader.read(self.data_file)), 2)

        reader = Reader(item_set=['93', '257', '795'])
        self.assertEqual(len(reader.read(self.data_file)), 3)
github PreferredAI / cornac / tests / cornac / data / test_reader.py View on Github external
def test_filter(self):
        reader = Reader(bin_threshold=4.0)
        data = reader.read(self.data_file)
        self.assertEqual(len(data), 8)
        self.assertListEqual([x[2] for x in data], [1] * len(data))

        reader = Reader(min_user_freq=2)
        self.assertEqual(len(reader.read(self.data_file)), 0)

        reader = Reader(min_item_freq=2)
        self.assertEqual(len(reader.read(self.data_file)), 0)

        reader = Reader(user_set=['76'], item_set=['93'])
        self.assertEqual(len(reader.read(self.data_file)), 1)

        reader = Reader(user_set=['76', '768'])
        self.assertEqual(len(reader.read(self.data_file)), 2)

        reader = Reader(item_set=['93', '257', '795'])
        self.assertEqual(len(reader.read(self.data_file)), 3)
github PreferredAI / cornac / tests / cornac / data / test_graph.py View on Github external
def test_get_node_degree(self):
        data = Reader().read('./tests/graph_data.txt', sep=' ')
        gmd = GraphModality(data=data)

        global_iid_map = OrderedDict()
        for raw_iid, raw_jid, val in data:
            global_iid_map.setdefault(raw_iid, len(global_iid_map))

        gmd.build(id_map=global_iid_map)

        degree = gmd.get_node_degree()

        self.assertEqual(degree.get(0)[0], 4)
        self.assertEqual(degree.get(0)[1], 1)
        self.assertEqual(degree.get(1)[0], 2)
        self.assertEqual(degree.get(1)[1], 1)
        self.assertEqual(degree.get(5)[0], 0)
        self.assertEqual(degree.get(5)[1], 1)
github PreferredAI / cornac / tests / cornac / eval_methods / test_base_method.py View on Github external
def test_from_splits(self):
        data = Reader().read('./tests/data.txt')
        try:
            BaseMethod.from_splits(train_data=None, test_data=None)
        except ValueError:
            assert True

        try:
            BaseMethod.from_splits(train_data=data, test_data=None)
        except ValueError:
            assert True

        try:
            BaseMethod.from_splits(train_data=data, test_data=[], exclude_unknowns=True)
        except ValueError:
            assert True

        bm = BaseMethod.from_splits(train_data=data[:-1], test_data=data[-1:])
github PreferredAI / cornac / tests / cornac / experiment / test_experiment.py View on Github external
def setUp(self):
        self.data = Reader().read('./tests/data.txt')
github PreferredAI / cornac / tests / cornac / experiment / test_experiment.py View on Github external
def test_with_cross_validation(self):
        Experiment(eval_method=CrossValidation(self.data + [(self.data[0][0], self.data[1][1], 5.0)],
                                               exclude_unknowns=False, verbose=True),
                   models=[PMF(1, 0)],
                   metrics=[Recall(1), FMeasure(1)],
                   verbose=True).run()
github PreferredAI / cornac / tests / cornac / data / test_text.py View on Github external
def test_tfidf_params(self):
        corpus = ['a b c', 'b c d d', 'c b e c f']
        ids = ['u1', 'u2', 'u3']

        modality = TextModality(corpus=corpus, ids=ids, max_vocab=6,
                                tfidf_params={
                                    'binary': False,
                                    'norm': 'l2',
                                    'use_idf': True,
                                    'smooth_idf': True,
                                    'sublinear_tf': False
                                }).build({'u1': 0, 'u2': 1, 'u3': 2})
        npt.assert_array_equal(modality.batch_tfidf([1]),
                               self.modality.batch_tfidf([1]))

        for k, v in {
            'binary': True,
            'norm': 'l1',
            'use_idf': False,
            'smooth_idf': False,
            'sublinear_tf': True
github PreferredAI / cornac / tests / cornac / data / test_text.py View on Github external
def test_build(self):
        TextModality().build()
        TextModality(corpus=['abc']).build()
        TextModality(corpus=['abc']).build({'b': 0})
        TextModality(corpus=['abc'], ids=['a']).build({'b': 0})
github PreferredAI / cornac / tests / cornac / data / test_text.py View on Github external
def test_build(self):
        TextModality().build()
        TextModality(corpus=['abc']).build()
        TextModality(corpus=['abc']).build({'b': 0})
        TextModality(corpus=['abc'], ids=['a']).build({'b': 0})