Exemplo n.º 1
0
    def test_cost_func_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([[64828197300.798]],
                        cost_func(X, y, theta),
                        rtol=0, atol=0.001)
Exemplo n.º 2
0
    def test_cost_func_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([[65591548106.457]],
                        cost_func(X, y, theta),
                        rtol=0, atol=0.001)
Exemplo n.º 3
0
    def test_cost_func_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([[54.242]],
                        cost_func(X, y, theta),
                        rtol=0, atol=0.001)
Exemplo n.º 4
0
    def test_cost_func_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([[43502644952.311]],
                        cost_func(X, y, theta),
                        rtol=0, atol=0.001)
Exemplo n.º 5
0
 def J(theta):
     return cost_func(X, y, theta)