def test_randlin():
    randlin = SG.Randlin(n_samples=100, n_features=10, n_informative=3,
            effective_rank=5, coef=True, bias=0.0, noise=1.0, random_state=0)

    X, y = randlin.regression_task()
    tasks.assert_regression(X, y, 100)
    assert_equal(X.shape, (100, 10), "X shape mismatch")
    assert_equal(y.shape, (100, 1), "y shape mismatch")

    c = randlin.ground_truth
    assert_equal(c.shape, (10,), "coef shape mismatch")
    assert_equal(sum(c != 0.0), 3, "Unexpected number of informative features")

    # Test that y ~= np.dot(X, c) + bias + N(0, 1.0)
    assert_approx_equal(np.std(y[:,0] - np.dot(X, c)), 1.0, significant=2)
Beispiel #2
0
    def test_assert_regression(self):
        # things that work:
        tasks.assert_regression(
                rnd('float32', 4, 2), rnd('float64', 4, 1))
        tasks.assert_regression(
                rnd('float64', 4, 2), rnd('float32', 4, 3))
        tasks.assert_regression(
                rnd('float64', 4, 2), rnd('float32', 4, 3), 4)

        # things that break:
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('int8', 4, 2), rnd('float32', 4, 1))        # X not float
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float32', 4, 2), rnd('int32', 4, 1))       # y not float
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float32', 4, 2), rnd('float32', 5, 1))     # y wrong len
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float32', 4, 2), rnd('float32', 4))        # y wrong rank
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float32', 4, 2), rnd('float32', 4, 7, 3))  # y wrong rank
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float32', 4, 2, 2), rnd('float32', 4, 1))  # X wrong rank
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float64', 4), rnd('float32', 4, 1))        # X wrong rank
        self.assertRaises(AssertionError, tasks.assert_regression,
                rnd('float64', 4, 3), rnd('float32', 4, 1), 5)  # N mismatch
def check_regression_XY(X, Y, N=None):
    assert_regression(X, y, N)
def test_sparse_uncorrelated():
    X, y = SG.SparseUncorrelated(n_samples=5, n_features=10,
            random_state=0).regression_task()
    tasks.assert_regression(X, y)
    assert_equal(X.shape, (5, 10), "X shape mismatch")
    assert_equal(y.shape, (5, 1), "y shape mismatch")