Esempio n. 1
0
    def test_reg_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]])
        _lambda = 1000000

        assert_allclose([[43514185803.375198]],
                        reg_cost_func(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Esempio n. 2
0
    def test_reg_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]])
        _lambda = 750

        assert_allclose([[69.706373]],
                        reg_cost_func(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Esempio n. 3
0
    def test_reg_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)
        _lambda = 1000000

        assert_allclose([[64828218577.393623]],
                        reg_cost_func(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Esempio n. 4
0
    def test_reg_cost_func_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 = ones((n + 1, 1), dtype=float64)
        _lambda = 0

        assert_allclose([[10.266]],
                        reg_cost_func(X, y, theta, _lambda),
                        rtol=0, atol=0.001)
Esempio n. 5
0
 def J(theta):
     return reg_cost_func(X, y, theta, _lambda)