Пример #1
0
    def test_reg_grad_data2_2(self):
        y = self.data2[:, -1:]
        X = self.data2[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = ones((n + 1, 1), dtype=float64)
        _lambda = 1000000

        assert_allclose([[-338407.808], [-759558338.468], [-1092403.298]],
                        reg_grad(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Пример #2
0
    def test_reg_grad_data2_1(self):
        y = self.data2[:, -1:]
        X = self.data2[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = ones((n + 1, 1), dtype=float64)
        _lambda = 0

        assert_allclose([[-338407.808], [-759579615.064], [-1113679.894]],
                        reg_grad(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Пример #3
0
    def test_reg_grad_data1_3(self):
        y = self.data1[:, -1:]
        X = self.data1[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = array([[-1], [2]])
        _lambda = 750

        assert_allclose([[9.480465], [104.783153]],
                        reg_grad(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Пример #4
0
    def test_reg_grad_data1_2(self):
        y = self.data1[:, -1:]
        X = self.data1[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = ones((n + 1, 1), dtype=float64)
        _lambda = 100

        assert_allclose([[3.320665], [25.265821]],
                        reg_grad(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Пример #5
0
    def test_reg_grad_data2_3(self):
        y = self.data2[:, -1:]
        X = self.data2[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = array([[-25.3], [32], [7.8]])
        _lambda = 1000000

        assert_allclose([[-276391.444681],
                         [-615660007.370213],
                         [-740838.968085]],
                        reg_grad(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Пример #6
0
    def test_reg_grad_data1_6(self):
        y = self.data1[:, -1:]
        X = self.data1[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = array([[-12.4], [23.56]])
        _lambda = 943

        def J(theta):
            return reg_cost_func(X, y, theta, _lambda)

        assert_allclose(reg_grad(X, y, theta, _lambda),
                        numerical_grad(J, theta, self.err),
                        rtol=0, atol=0.001)
Пример #7
0
    def test_reg_grad_data1_4(self):
        y = self.data1[:, -1:]
        X = self.data1[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = -8.4 * ones((n + 1, 1), dtype=float64)
        _lambda = 0.762

        def J(theta):
            return reg_cost_func(X, y, theta, _lambda)

        assert_allclose(reg_grad(X, y, theta, _lambda),
                        numerical_grad(J, theta, self.err),
                        rtol=0, atol=0.001)