Esempio n. 1
0
def test_evaluate_score_ndim(X, y):
    """Test fit() works for both y.ndim == 1 and y.ndim == 2. Two test cases
    are listed in @pytest.mark.parametrize()
    """
    sr = SimpleRegressor(random_state=0)
    print(f"Data ndim: X: {X.shape}, y: {y.shape}")
    sr.fit(X, y)
Esempio n. 2
0
def test_shuffle_cross_validation():
    # somewhat nonlinear design with sorted target
    rng = np.random.RandomState(42)
    X = rng.normal(size=(100, 10))
    w = rng.normal(size=(10, ))
    y = np.dot(X, w)
    y = .1 * y**2 + 2 * y
    # throws off linear model if we sort
    sorting = np.argsort(y)
    X = pd.DataFrame(X[sorting, :])
    y = pd.Series(y[sorting])
    sr = SimpleRegressor(shuffle=False).fit(X, y)
    assert sr.log_[-2].r2 < 0.1
    sr = SimpleRegressor().fit(X, y)
    assert sr.log_[-2].r2 > .9
Esempio n. 3
0
def test_regression_boston():
    boston = load_boston()
    data = data_df_from_bunch(boston)
    er = SimpleRegressor()
    er.fit(data, target_col='target')

    # test nupmy array
    er = SimpleRegressor()
    er.fit(boston.data, boston.target)