Logistic regression Newton's Method Newton Method Lecture II
In this picture the logistic regression cost function , Newtons Method and gradient and Hessian is defined. How to get this function that is also defined by the video tutorial link.
H is a hypothesis function and as per this problem h is define by
In Matlab h is define as follows
% Initialize fitting parameters theta = zeros(n+1, 1); % Define the sigmoid function g = inline('1.0 ./ (1.0 + exp(-z))'); % Calculate the hypothesis function z = x * theta; h = g(z); % Calculate gradient and hessian. % The formulas below are equivalent to the summation formulas % given in the picture. grad = (1/m).*x' * (h-y); H = (1/m).*x' * diag(h) * diag(1-h) * x;
Now I am confused that how could this last two line of Matlab code is
grad = (1/m).*x' * (h-y); H = (1/m).*x' * diag(h) * diag(1-h) * x;
equivalent to gradient and Hessian formula?
Thank you in advance