コード例 #1
0
    def test_recall(self):
        rec = Recall()

        self.assertEqual(rec.type, "ranking")
        self.assertEqual(rec.name, "Recall@-1")

        self.assertEqual(1, rec.compute(np.asarray([1]), np.asarray([0])))

        ground_truth = np.asarray([1, 0, 1])  # [1, 0, 1]
        rec_list = np.asarray([0, 2, 1])  # [1, 1, 1]
        self.assertEqual(1, rec.compute(ground_truth, rec_list))

        ground_truth = np.asarray([0, 0, 1])  # [0, 0, 1]
        rec_list = np.asarray([1, 2, 0])  # [1, 1, 1]
        self.assertEqual(1, rec.compute(ground_truth, rec_list))

        rec_2 = Recall(k=2)
        self.assertEqual(rec_2.k, 2)

        ground_truth = np.asarray([0, 0, 1])  # [0, 0, 1]
        rec_list = np.asarray([1, 2, 0])  # [1, 1, 1]
        self.assertEqual(1, rec_2.compute(ground_truth, rec_list))
コード例 #2
0
ファイル: test_ranking.py プロジェクト: Andrew-DungLe/cornac
def test_recall():
    rec = Recall()

    assert rec.type == 'ranking'
    assert rec.name == 'Recall@-1'

    assert 1 == rec.compute(np.asarray([1]), np.asarray([0]))

    ground_truth = np.asarray([1, 0, 1])  # [1, 0, 1]
    rec_list = np.asarray([0, 2, 1])  # [1, 1, 1]
    assert 1 == rec.compute(ground_truth, rec_list)

    ground_truth = np.asarray([0, 0, 1])  # [0, 0, 1]
    rec_list = np.asarray([1, 2, 0])  # [1, 1, 1]
    assert 1 == rec.compute(ground_truth, rec_list)

    rec_2 = Recall(k=2)
    assert rec_2.k == 2

    ground_truth = np.asarray([0, 0, 1])  # [0, 0, 1]
    rec_list = np.asarray([1, 2, 0])  # [1, 1, 1]
    assert 1 == rec_2.compute(ground_truth, rec_list)