def test_cost_func_data3_3(self, data3): y = data3[:, -1:] X = 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)
def test_cost_func_data4_1(self, data4): y = data4[:, -1:] X = 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 isclose(0.693, cost_func(X, y, theta), rtol=0, atol=0.001, equal_nan=False)
def test_cost_func_data4_2(self, data4): y = data4[:, -1:] X = 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)
def J(theta): return cost_func(X, y, theta)