def test_grad_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_allclose([[0.043], [2.566], [2.647]], grad(X, y, theta), rtol=0, atol=0.001, equal_nan=False)
def test_grad_data3_2(self): y = self.data3[:, -1:] X = self.data3[:, :-1] m, _ = X.shape intercept = ones((m, 1), dtype=float64) X = append(intercept, X, axis=1) theta = array([[-0.1], [0.4], [-0.4]]) assert_allclose([[-0.134], [-8.275], [-18.564]], grad(X, y, theta), rtol=0, atol=0.001, equal_nan=False)
def test_grad_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_allclose([[-0.1000], [-12.0092], [-11.2628]], grad(X, y, theta), rtol=0, atol=5e-05, equal_nan=False)
def test_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 = zeros((n + 1, 1), dtype=float64) assert_allclose(array([[0.151], [0.225], [11.154], [9.838], [2.534], [4.887], [3.733], [0.044], [3.686]]), grad(X, y, theta), rtol=0, atol=0.001, equal_nan=False)
def test_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) assert_allclose(array([[-0.349], [-1.698], [-49.293], [-24.715], [-7.734], [-35.013], [-12.263], [-0.192], [-12.935]]), grad(X, y, theta), rtol=0, atol=0.001, equal_nan=False)
def test_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.145 * ones((n + 1, 1), dtype=float64) 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, equal_nan=False)
def test_grad_data4_5(self): y = self.data4[:, -1:] X = self.data4[:, :-1] m, _ = X.shape intercept = ones((m, 1), dtype=float64) X = append(intercept, X, axis=1) theta = array([[-0.198], [0.25], [-0.234], [-0.793], [0.123], [-0.378], [0.423], [-0.678], [-0.3]]) 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, equal_nan=False)