Пример #1
0
    def test_all_fn(self):
        ranks = np.array([[1, 2, 3], [2, 3, 1], [3, 1, 2]])
        labels = np.array([2, 3, 1])

        _, recall = precision_recall(ranks, labels)

        assert np.all(recall == np.array([0, 0, 0]))
Пример #2
0
    def test_filter_existing_class(self):
        ranks = np.array([[1, 2, 3], [2, 3, 1], [3, 1, 2]])
        labels = np.array([1, 2, 3])
        precision, recall = precision_recall(ranks, labels, classes=np.array([1]))

        assert np.all(precision == np.array([1]))
        assert np.all(recall == np.array([1]))
Пример #3
0
    def test_all_tp(self):
        ranks = np.array([[1, 2, 3], [2, 3, 1], [3, 1, 2]])
        labels = np.array([1, 2, 3])
        precision, _ = precision_recall(ranks, labels)

        assert np.all(precision == np.array([1, 1, 1]))
Пример #4
0
    def test_throws_exception_if_labels_and_ranks_are_different_lengths(self):
        ranks = np.array([[2, 3, 1], [3, 1, 2]])
        labels = np.array([1, 2, 3])

        with pytest.raises(ValueError):
            precision, _ = precision_recall(ranks, labels)
Пример #5
0
    def test_filter_nonexisting_class(self):
        ranks = np.array([[1, 2, 3], [2, 3, 1], [3, 1, 2]])
        labels = np.array([1, 2, 3])

        with pytest.raises(ValueError):
            precision, _ = precision_recall(ranks, labels, classes=np.array([4]))
Пример #6
0
    def test_no_fp_and_no_tp(self):
        ranks = np.array([[4, 2, 3], [4, 3, 1], [4, 1, 2]])
        labels = np.array([3, 1, 2])
        precision, _ = precision_recall(ranks, labels)

        assert np.all(precision == np.array([0, 0, 0]))