Beispiel #1
0
def test_is_label_indicator_matrix():
    for group, group_examples in iteritems(EXAMPLES):
        if group == "multilabel-indicator":
            assert_, exp = assert_true, "True"
        else:
            assert_, exp = assert_false, "False"
        for example in group_examples:
            assert_(
                is_label_indicator_matrix(example), msg="is_label_indicator_matrix(%r) should be %s" % (example, exp)
            )
def test_is_label_indicator_matrix():
    for group, group_examples in iteritems(EXAMPLES):
        if group == 'multilabel-indicator':
            assert_, exp = assert_true, 'True'
        else:
            assert_, exp = assert_false, 'False'
        for example in group_examples:
            assert_(is_label_indicator_matrix(example),
                    msg='is_label_indicator_matrix(%r) should be %s'
                    % (example, exp))
Beispiel #3
0
def test_is_label_indicator_matrix():
    for group, group_examples in iteritems(EXAMPLES):
        if group == 'multilabel-indicator':
            assert_, exp = assert_true, 'True'
        else:
            assert_, exp = assert_false, 'False'
        for example in group_examples:
            assert_(is_label_indicator_matrix(example),
                    msg='is_label_indicator_matrix(%r) should be %s' %
                    (example, exp))
def test_is_label_indicator_matrix():
    for group, group_examples in iteritems(EXAMPLES):
        if group in ['multilabel-indicator']:
            dense_assert_, dense_exp = assert_true, 'True'
        else:
            dense_assert_, dense_exp = assert_false, 'False'

        for example in group_examples:
            # Only mark explicitly defined sparse examples as valid sparse
            # multilabel-indicators
            if group == 'multilabel-indicator' and issparse(example):
                sparse_assert_, sparse_exp = assert_true, 'True'
            else:
                sparse_assert_, sparse_exp = assert_false, 'False'

            if (issparse(example)
                    or (hasattr(example, '__array__')
                        and np.asarray(example).ndim == 2
                        and np.asarray(example).dtype.kind in 'biuf'
                        and np.asarray(example).shape[1] > 0)):
                examples_sparse = [
                    sparse_matrix(example) for sparse_matrix in [
                        coo_matrix, csc_matrix, csr_matrix, dok_matrix,
                        lil_matrix
                    ]
                ]
                for exmpl_sparse in examples_sparse:
                    sparse_assert_(is_label_indicator_matrix(exmpl_sparse),
                                   msg=('is_label_indicator_matrix(%r)'
                                        ' should be %s') %
                                   (exmpl_sparse, sparse_exp))

            # Densify sparse examples before testing
            if issparse(example):
                example = example.toarray()

            dense_assert_(is_label_indicator_matrix(example),
                          msg='is_label_indicator_matrix(%r) should be %s' %
                          (example, dense_exp))
Beispiel #5
0
def test_is_label_indicator_matrix():
    for group, group_examples in iteritems(EXAMPLES):
        if group in ['multilabel-indicator']:
            dense_assert_, dense_exp = assert_true, 'True'
        else:
            dense_assert_, dense_exp = assert_false, 'False'

        for example in group_examples:
            # Only mark explicitly defined sparse examples as valid sparse
            # multilabel-indicators
            if group == 'multilabel-indicator' and issparse(example):
                sparse_assert_, sparse_exp = assert_true, 'True'
            else:
                sparse_assert_, sparse_exp = assert_false, 'False'

            if (issparse(example) or
                (hasattr(example, '__array__') and
                 np.asarray(example).ndim == 2 and
                 np.asarray(example).dtype.kind in 'biuf' and
                 np.asarray(example).shape[1] > 0)):
                examples_sparse = [sparse_matrix(example)
                                   for sparse_matrix in [coo_matrix,
                                                         csc_matrix,
                                                         csr_matrix,
                                                         dok_matrix,
                                                         lil_matrix]]
                for exmpl_sparse in examples_sparse:
                    sparse_assert_(is_label_indicator_matrix(exmpl_sparse),
                                   msg=('is_label_indicator_matrix(%r)'
                                   ' should be %s')
                                   % (exmpl_sparse, sparse_exp))

            # Densify sparse examples before testing
            if issparse(example):
                example = example.toarray()

            dense_assert_(is_label_indicator_matrix(example),
                          msg='is_label_indicator_matrix(%r) should be %s'
                          % (example, dense_exp))
Beispiel #6
0
def test_is_label_indicator_matrix():
    assert_true(is_label_indicator_matrix(np.random.randint(2, size=(10, 10))))

    assert_false(is_label_indicator_matrix([[1], [2], [0, 1]]))
    assert_false(is_label_indicator_matrix([[1], [2]]))
    assert_false(is_label_indicator_matrix([[1], [2], []]))
    assert_false(is_label_indicator_matrix([[1], [0, 2], []]))
    assert_false(is_label_indicator_matrix(range(10)))
    assert_false(is_label_indicator_matrix(np.arange(10)))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(9), (3, 3))))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(10), (-1, 1))))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(10), (1, -1))))
    assert_false(is_label_indicator_matrix(np.random.randint(2, size=(10, ))))
    assert_false(is_label_indicator_matrix(np.random.randint(2, size=(10, 1))))
def test_is_label_indicator_matrix():
    assert_true(is_label_indicator_matrix(np.random.randint(2, size=(10, 10))))

    assert_false(is_label_indicator_matrix([[1], [2], [0, 1]]))
    assert_false(is_label_indicator_matrix([[1], [2]]))
    assert_false(is_label_indicator_matrix([[1], [2], []]))
    assert_false(is_label_indicator_matrix([[1], [0, 2], []]))
    assert_false(is_label_indicator_matrix(range(10)))
    assert_false(is_label_indicator_matrix(np.arange(10)))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(9), (3, 3))))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(10), (-1, 1))))
    assert_false(is_label_indicator_matrix(np.reshape(np.arange(10), (1, -1))))
    assert_false(is_label_indicator_matrix(np.random.randint(2, size=(10, ))))
    assert_false(is_label_indicator_matrix(np.random.randint(2, size=(10, 1))))