Exemplo n.º 1
0
def test_split_1(data):
    ds = Splitter(10, test_size=0.3)
    train, test = ds.split(data[0])
    for d in train:
        assert d in data[0]
    for d in test:
        assert d in data[0]
Exemplo n.º 2
0
def test_split_2(data):
    np.random.seed(123456)
    ds = Splitter(10, test_size=0.1)
    with pytest.raises(ValueError):
        ds.split(data[1][1:])
    _, test = ds.split(data[1])
    assert test[0] in data[1]
Exemplo n.º 3
0
def test_data_splitter_2():
    np.random.seed(123456)
    ds = Splitter(10)
    assert ds.size == 10
    train, test = ds.split()
    assert train.size == 8
    assert test.size == 2
Exemplo n.º 4
0
def test_split_1(data):
    np.random.seed(123456)
    ds = Splitter(10, test_size=0.3)
    train, test = ds.split(data[0])
    for d in train:
        assert d in data[0]
    for d in test:
        assert d in data[0]
Exemplo n.º 5
0
def test_split_2(data):
    ds = Splitter(10, test_size=0.1)
    try:
        ds.split(data[1][1:])
    except ValueError:
        assert True
    else:
        assert False, 'should got ValueError'
    _, test = ds.split(data[1])
    assert test[0] in data[1]
Exemplo n.º 6
0
def test_cv_1(data):
    ds = Splitter(10, test_size=0, cv=5)
    cv = ds.cv()
    tmp = []
    for x, x_ in cv:
        assert isinstance(x, np.ndarray)
        assert isinstance(x_, np.ndarray)
        assert x.size + x_.size == 10
        tmp.append(x_)
    tmp = np.concatenate(tmp)
    tmp = np.sort(tmp)
    assert np.array_equal(tmp, data[0])
Exemplo n.º 7
0
def test_cv_3(data):
    ds = Splitter(10, test_size=0, cv=data[5])
    cv = ds.cv()
    tmp = []
    for x, x_ in cv:
        assert isinstance(x, np.ndarray)
        assert isinstance(x_, np.ndarray)
        assert x.size + x_.size == 10
        tmp.append(x_)
    sizes = np.sort([x.size for x in tmp])
    assert np.array_equal(sizes, [2, 4, 4])
    tmp = np.concatenate(tmp)
    tmp = np.sort(tmp)
    assert np.array_equal(tmp, data[0])
Exemplo n.º 8
0
def test_cv_2(data):
    ds = Splitter(10, test_size=0.2, cv=4)
    cv = ds.cv()
    tmp = []
    tmp_x_ = []
    for x, x_, _x_ in cv:
        assert isinstance(x, np.ndarray)
        assert isinstance(x_, np.ndarray)
        assert isinstance(_x_, np.ndarray)
        assert x.size + x_.size == 8
        assert _x_.size == 2
        tmp_x_.append(_x_)
        tmp.append(x_)
    assert np.array_equal(tmp_x_[1], tmp_x_[3])
    tmp = np.concatenate(tmp)
    assert tmp.size == 8
    tmp = np.concatenate([tmp, _x_])
    tmp = np.sort(tmp)
    assert np.array_equal(tmp, data[0])
Exemplo n.º 9
0
def test_roll_2():
    ds = Splitter(10, test_size=0.3)
    train, test = ds.split()
    assert train.size == 7
    assert test.size == 3
    ds.roll(test_size=0.3)
    train_, test_ = ds.split()
    assert not np.array_equal(train, train_)
    assert not np.array_equal(test, test_)
Exemplo n.º 10
0
def test_roll_1():
    ds = Splitter(10, test_size=0.3)
    train, test = ds.split()
    assert train.size == 7
    assert test.size == 3
    ds.roll(test_size=0.4)
    train, test = ds.split()
    assert train.size == 6
    assert test.size == 4
Exemplo n.º 11
0
def test_roll_1():
    np.random.seed(123456)
    ds = Splitter(10, test_size=0.3)
    train, test = ds.split()
    assert train.size == 7
    assert test.size == 3
    ds.roll(test_size=0.4)
    train, test = ds.split()
    assert train.size == 6
    assert test.size == 4
Exemplo n.º 12
0
def test_split_3(data):
    ds = Splitter(10)
    try:
        ds.split(data[0])
        ds.split(data[1])
        ds.split(data[2])
        ds.split(data[3])
        ds.split(data[4])
    except TypeError:
        assert False, 'should not got TypeError'
    else:
        assert True

    try:
        ds.split([1])
    except ValueError:
        assert True
    else:
        assert False, 'should got ValueError'

    try:
        ds.split('ss')
    except TypeError:
        assert True
    else:
        assert False, 'should got TypeError'
Exemplo n.º 13
0
def test_data_splitter_2():
    ds = Splitter(10)
    assert ds.size == 10
    train, test = ds.split()
    assert train.size == 8
    assert test.size == 2
Exemplo n.º 14
0
def test_split_4(data):
    ds = Splitter(10)
    x, x_, y, y_ = ds.split(data[3], data[4])
    assert isinstance(x, np.ndarray)
Exemplo n.º 15
0
def test_split_3(data):
    np.random.seed(123456)
    ds = Splitter(10)
    ds.split(data[0])
    ds.split(data[1])
    ds.split(data[2])
    ds.split(data[3])
    ds.split(data[4])

    with pytest.raises(ValueError):
        ds.split([1])

    with pytest.raises(TypeError):
        ds.split(data[0])
        ds.split('ss')
Exemplo n.º 16
0
def test_split_4(data):
    np.random.seed(123456)
    ds = Splitter(10)
    x, x_, y, y_ = ds.split(data[3], data[4])
    assert isinstance(x, np.ndarray)