예제 #1
0
    def test_cost_func_data4_3(self):
        y = self.data4[:, -1:]
        X = self.data4[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = -0.1 * ones((n + 1, 1), dtype=float64)

        assert_allclose(14.419,
                        cost_func(X, y, theta),
                        rtol=0,
                        atol=0.001,
                        equal_nan=False)
예제 #2
0
    def test_cost_func_data3_3(self):
        y = self.data3[:, -1:]
        X = self.data3[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = array([[-24], [0.2], [0.2]])

        assert isclose(0.218,
                       cost_func(X, y, theta),
                       rtol=0,
                       atol=0.001,
                       equal_nan=False)
예제 #3
0
    def test_cost_func_data4_2(self):
        y = self.data4[:, -1:]
        X = self.data4[:, :-1]
        m, n = X.shape
        intercept = ones((m, 1), dtype=float64)
        X = append(intercept, X, axis=1)
        theta = array([[-0.1], [0.4], [-0.4], [-0.4], [0.4], [-0.4], [0.4],
                       [-0.4], [-0.4]])

        assert_allclose(40.216,
                        cost_func(X, y, theta),
                        rtol=0,
                        atol=0.001,
                        equal_nan=False)
예제 #4
0
    def test_cost_func_data3_1(self):

        y = self.data3[:, -1:]
        X = self.data3[:, :-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 isclose(0.693,
                       cost_func(X, y, theta),
                       rtol=0,
                       atol=0.001,
                       equal_nan=False)
예제 #5
0
 def J(theta):
     return cost_func(X, y, theta)