# HG changeset patch # User Jeff Hammel # Date 1504541665 25200 # Node ID f34110e28a0adbe53eafa7cc8c6eab098817bbd4 # Parent 3713c6733990105311bb71e06c4b7d069194fd91 [logistic regression] we have a working cost function diff -r 3713c6733990 -r f34110e28a0a tests/test_logistic_regression.py --- a/tests/test_logistic_regression.py Mon Sep 04 08:59:52 2017 -0700 +++ b/tests/test_logistic_regression.py Mon Sep 04 09:14:25 2017 -0700 @@ -21,7 +21,7 @@ expected_cost = 6.000064773192205 cost = logistic_regression.cost_function(w, b, X, Y) - print cost + assert abs(cost - expected_cost) < 1e-6 if __name__ == '__main__': unittest.main() diff -r 3713c6733990 -r f34110e28a0a tvii/logistic_regression.py --- a/tvii/logistic_regression.py Mon Sep 04 08:59:52 2017 -0700 +++ b/tvii/logistic_regression.py Mon Sep 04 09:14:25 2017 -0700 @@ -44,7 +44,7 @@ """ m = X.shape[1] - A = w.T*X # compute activation + A = sigmoid(w.T*X + b)# compute activation def cost_function(w, b, X, Y): @@ -58,9 +58,9 @@ """ m = X.shape[1] - A = w.T*X - cost = Y*np.log(A) + (1 - Y)*np.log(1 - A) - return (1./m)*cost + A = sigmoid(np.dot(w.T, X) + b) + cost = np.sum(Y*np.log(A) + (1 - Y)*np.log(1 - A)) + return (-1./m)*cost def logistic_regression(_):