From 8c100a3f497061966fb4a66db676e851a0891e1d Mon Sep 17 00:00:00 2001 From: neingeist Date: Tue, 14 Oct 2014 07:40:42 +0200 Subject: [PATCH] Compute the cost function for logistic regression --- ex2/costFunction.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ex2/costFunction.m b/ex2/costFunction.m index 1d98fbe..1f49581 100644 --- a/ex2/costFunction.m +++ b/ex2/costFunction.m @@ -7,7 +7,7 @@ function [J, grad] = costFunction(theta, X, y) % Initialize some useful values m = length(y); % number of training examples -% You need to return the following variables correctly +% You need to return the following variables correctly J = 0; grad = zeros(size(theta)); @@ -19,7 +19,7 @@ grad = zeros(size(theta)); % % Note: grad should have the same dimensions as theta % - +J = 1/m * (-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta)));