示例#1
0
 def test_regularized_cost_function(self):
     dimension = 6
     X_mapped = map_feature(self.X[:, 0], self.X[:, 1], dimension)
     m, n = X_mapped.shape
     X_mapped = np.hstack((np.ones((m, 1)), X_mapped))
     theta = np.zeros((n + 1, 1))
     lamda = 1.0
     cost_loop = regularized_cost_function_loop(X_mapped, self.y, theta,
                                                lamda)
     cost = regularized_cost_function(X_mapped, self.y, theta, lamda)
     self.assertAlmostEqual(cost_loop, 0.69314718056, places=5)
     self.assertAlmostEqual(cost, 0.69314718056, places=5)
示例#2
0
 def test_regularized_cost_function(self):
     X = np.hstack((np.ones((self.m,1)), self.X))
     lamda = 1.0
     cost = regularized_cost_function_loop(self.theta1, self.theta2, X, self.y, lamda)
     self.assertAlmostEqual(cost, 0.383770, places=6)