Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function [cost, gradient] = cost_logistic(a, x, y)
cost = 0;
gradient = 0;
t = a(1)+a(2).*x;
sigma = 1./(1+exp(-t));
cost = sum(-y.*log(sigma)- (1-y).*log(1-sigma));
costFun = @ (a) sum(-y.*log((1./(1+exp(-(a(1)+a(2).*x)))))-(1-y).*log(1-(1./(1+exp(-(a(1)+a(2).*x))))));
gradient = (1/length(x))*sum((sigma-y).*t);
ai = [0 0];
% Set options for fminunc
options = optimset('GradObj','on','MaxIter',400);
% Run fminunc to obtain the optimal theta
% This function will return theta and the cost
[theta, cost] = fminunc(costFun, ai);
t = theta(1)+theta(2).*x;
sigma = 1./(1+exp(-t));
plot(x,y,'xb', x, sigma);
title('Regression')
xlabel('Temp (Degrees F)')
ylabel('Pass or Fail (1 or 0)')
end