def test_reg_grad_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 = -0.1 * ones((n + 1, 1), dtype=float64) _lambda = 100 assert_allclose(array([[-0.349], [-1.710], [-49.305], [-24.727], [-7.747], [-35.026], [-12.276], [-0.205], [-12.948]]), reg_grad(X, y, theta, _lambda), rtol=0, atol=0.001, equal_nan=False)
def test_reg_grad_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) _lambda = 1000000 assert_allclose(array([[-0.348958], [-131.906250], [-179.501291], [-154.923177], [-137.942708], [-165.221354], [-142.471614], [-130.400435], [-143.143226]]), reg_grad(X, y, theta, _lambda), rtol=0, atol=0.001, equal_nan=False)
def test_reg_grad_data4_1(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) _lambda = 10 assert_allclose(array([[-0.349], [-1.699], [-49.294], [-24.716], [-7.736], [-35.014], [-12.265], [-0.193], [-12.936]]), reg_grad(X, y, theta, _lambda), rtol=0, atol=0.001, equal_nan=False)
def test_reg_grad_data4_6(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.238 * ones((n + 1, 1), dtype=float64) _lambda = 975032 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, equal_nan=False)