def test_cost_func_data1_3(self, data1): y = data1[:, -1:] X = data1[:, :-1] m, n = X.shape intercept = ones((m, 1), dtype=float64) X = append(intercept, X, axis=1) theta = array([[-1], [2]]) assert_allclose([[54.242]], cost_func(X, y, theta), rtol=0, atol=0.001)
def test_cost_func_data1_2(self, data1): y = data1[:, -1:] X = 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) assert_allclose([[10.266]], cost_func(X, y, theta), rtol=0, atol=0.001)
def test_cost_func_data2_1(self, data2): y = data2[:, -1:] X = data2[:, :-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([[65591548106.457]], cost_func(X, y, theta), rtol=0, atol=0.001)
def test_cost_func_data2_3(self, data2): y = data2[:, -1:] X = 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]]) assert_allclose([[43502644952.311]], cost_func(X, y, theta), rtol=0, atol=0.001)
def J(theta): return cost_func(X, y, theta)