Ejemplo n.º 1
0
def test_integration_nonperfect_linear():
    X, y = data_gen(nrows=100, Non_perfect=True)
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    scores = cross_validation(lm(), X=X_train, y=y_train, shuffle=False)
    summary = summary_cv(scores)
    assert summary['mean'] < 1 and summary['median'] < 1 and summary[
        'sd'] > 0, 'Non-perfect linear relation test does not give correct summary'
Ejemplo n.º 2
0
def test_integration_nonperfect_linear():
    X, y = data_gen(nrows=100, Non_perfect=True)
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    scores = cross_validation(lm(), X=X_train, y=y_train, shuffle=False)
    summary = summary_cv(scores)
    assert summary['mean'] < 1 and summary['median'] < 1 and summary[
        'sd'] > 0, 'Non-perfect linear relation test does not give correct summary'
Ejemplo n.º 3
0
def test_index_match():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X, y)

    v1 = X_train.append(X_test).X0.sort_values().as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.sort_values().as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(v3, v4)), "X/y_train + X/y_test is not a complete set of X/y"
Ejemplo n.º 4
0
def test_shuffle_False():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=False)

    v1 = X_train.append(X_test).X0.as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(v3, v4)), "X/y_train + X/y_test is shuffled while `shuffle=False`"
Ejemplo n.º 5
0
def test_shuffle_False_random_state_effect():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=False, random_state=12345)

    v1 = X_train.append(X_test).X0.as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(v3, v4)), "`shuffle=False`: random state should have no effect"
Ejemplo n.º 6
0
def test_shuffle_False():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=False)

    v1 = X_train.append(X_test).X0.as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(
        v3, v4)), "X/y_train + X/y_test is shuffled while `shuffle=False`"
Ejemplo n.º 7
0
def test_index_match():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X, y)

    v1 = X_train.append(X_test).X0.sort_values().as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.sort_values().as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(
        v3, v4)), "X/y_train + X/y_test is not a complete set of X/y"
Ejemplo n.º 8
0
def test_shuffle_as_boolean():
    with pytest.raises(TypeError('`shuffle` must be True or False')):
        train_test_split(X=X, y=y, shuffle='1')
    with pytest.raises(TypeError('`shuffle` must be True or False')):
        train_test_split(X=X, y=y, shuffle=1)
    with pytest.raises(TypeError('`shuffle` must be True or False')):
        train_test_split(X=X, y=y, shuffle=1.0)
Ejemplo n.º 9
0
def test_shuffle_False_random_state_effect():
    X, y = data_gen(nrows=100)
    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        shuffle=False,
                                                        random_state=12345)

    v1 = X_train.append(X_test).X0.as_matrix()
    v2 = X.X0.as_matrix()
    v3 = y_train.append(y_test).y.as_matrix()
    v4 = y.as_matrix().flatten()
    assert (np.array_equal(v1, v2) and np.array_equal(
        v3, v4)), "`shuffle=False`: random state should have no effect"
Ejemplo n.º 10
0
def test_test_size_range_small_than_0():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, test_size=- 0.1)
Ejemplo n.º 11
0
def test_random_state_range():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, random_state=-10)
Ejemplo n.º 12
0
def test_test_size_range_small_than_0():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, test_size=-0.1)
Ejemplo n.º 13
0
def test_test_size_as_number():

    with pytest.raises(TypeError('`test_size` must be a number')):
        train_test_split(X=X, y=y, test_size='0.25')
Ejemplo n.º 14
0
def test_shuffle_as_boolean_not_string():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, shuffle='1')
Ejemplo n.º 15
0
def test_random_state_as_number():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, random_state='10')
Ejemplo n.º 16
0
def test_X_y_match():
    X, y = data_gen()
    y = y[0:90]
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 17
0
def test_X_y_Nrows():
    X, y = data_gen(nrows=2)
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 18
0
def test_X_y_Nrows():
    X, y = data_gen(nrows=2)
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 19
0
def test_random_state_range():
    with pytest.raises(TypeError('`random_state` must be nonnegative')):
        train_test_split(X=X, y=y, random_state=-10)
Ejemplo n.º 20
0
def test_random_state_as_number():
    with pytest.raises(TypeError('`random_state` must be a number or None')):
        train_test_split(X=X, y=y, random_state='10')
Ejemplo n.º 21
0
def test_test_size_range():
    with pytest.raises(TypeError('`test_size` must be between 0 and 1')):
        train_test_split(X=X, y=y, test_size=2)
    with pytest.raises(TypeError('`test_size` must be between 0 and 1')):
        train_test_split(X=X, y=y, test_size=-1)
Ejemplo n.º 22
0
def test_dimension_match():
    X, y = data_gen(nrows=10)
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    assert ((X_train.shape[0] + X_test.shape[0]) == X.shape[0] and (y_train.shape[0] + y_test.shape[0]) == y.shape[
        0]), "total rows of X/y_train and Xy_test doesn't match nrows of X/y"
Ejemplo n.º 23
0
def test_X_y_match():
    X, y = data_gen()
    y = y[0:90]
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 24
0
def test_y_one_column():
    with pytest.raises(TypeError('`y` is more than one feature')):
        train_test_split(X=X, y=y_2)
Ejemplo n.º 25
0
def test_y_as_dataframe():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y="y")
Ejemplo n.º 26
0
def test_y_one_column():
    X, y = data_gen()
    y = X
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 27
0
def test_y_one_column():
    X, y = data_gen()
    y = X
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y)
Ejemplo n.º 28
0
def test_X_y_match():
    with pytest.raises(TypeError("dim of `X` doesn't equal dim of `y`")):
        train_test_split(X=X_longer, y=y)
Ejemplo n.º 29
0
def test_dimension_match():
    X, y = data_gen(nrows=10)
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    assert ((X_train.shape[0] + X_test.shape[0]) == X.shape[0]
            and (y_train.shape[0] + y_test.shape[0]) == y.shape[0]
            ), "total rows of X/y_train and Xy_test doesn't match nrows of X/y"
Ejemplo n.º 30
0
def test_X_as_dataframe():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X="X", y=y)
Ejemplo n.º 31
0
def test_y_as_dataframe():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y="y")
Ejemplo n.º 32
0
def test_test_size_as_number():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, test_size='0.5')
Ejemplo n.º 33
0
def test_X_as_dataframe():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X="X", y=y)
Ejemplo n.º 34
0
def test_shuffle_as_boolean_not_string():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, shuffle='1')
Ejemplo n.º 35
0
def test_test_size_as_number():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, test_size='0.5')
Ejemplo n.º 36
0
def test_shuffle_as_boolean_not_numeric():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, shuffle=1.0)
Ejemplo n.º 37
0
def test_shuffle_as_boolean_not_numeric():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, shuffle=1.0)
Ejemplo n.º 38
0
def test_random_state_as_number():
    X, y = data_gen()
    with pytest.raises(TypeError):
        train_test_split(X=X, y=y, random_state='10')
Ejemplo n.º 39
0
def test_test_size_range_large_than_1():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, test_size=1.1)
Ejemplo n.º 40
0
def test_test_size_range_large_than_1():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, test_size=1.1)
Ejemplo n.º 41
0
def test_random_state_range():
    X, y = data_gen()
    with pytest.raises(ValueError):
        train_test_split(X=X, y=y, random_state=-10)
Ejemplo n.º 42
0
def test_X_y_Nrows():
    with pytest.raises(
            TypeError('sample size is less than 3, too small for splitting')):
        train_test_split(X=X.iloc[0:2, :], y=y.iloc[0:2, :])