Logistic regression Newton's Method Newton Method Lecture II

Logistic regression cost function

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

Hypothesis Function

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.