Exemple #1
0
    def test_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)

        assert_allclose([[-338407.808], [-759579615.064], [-1113679.894]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #2
0
    def test_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]])

        assert_allclose([[-276391.445], [-616340858.434], [-906796.414]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #3
0
    def test_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 = zeros((n + 1, 1), dtype=float64)

        assert_allclose([[-340412.659], [-764209128.191], [-1120367.702]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #4
0
    def test_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]])

        assert_allclose([[9.480], [89.319]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #5
0
    def test_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)

        assert_allclose([[3.321], [24.235]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #6
0
    def test_grad_data1_1(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 = zeros((n + 1, 1), dtype=float64)

        assert_allclose([[-5.839], [-65.329]],
                        grad(X, y, theta),
                        rtol=0, atol=0.001)
Exemple #7
0
    def test_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([[3.46], [-2.76]])

        def J(theta):
            return cost_func(X, y, theta)

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