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_logisticV3(a, x, y)
% cost_logisticV3 Compute cost and gradient for logistic regression
% cost = cost_logistic(theta, X, y) computes the cost of using theta as the
% parameter for logistic regression and the gradient of the cost
% w.r.t. to the parameters.
% ====================== YOUR CODE HERE ======================
% Compute the cost of a particular choice of a. Compute the partial derivatives and set grad to the partial derivatives of the cost w.r.t. each parameter in theta
cost = 0; %initialize values
gradient = 0; %initalize a gradient
t = a(1).*(x.^0)+a(2).*x; %time function
sigma = 1./(1+exp(-t)); %calculate sigma
cost = sum(-y.*log(sigma)- (1-y).*log(1-sigma)); %Calculation of cost
costFunction = @ (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); %Calculation of gradient
ai = [0 0]; %initialize a value for a
%---------------------- Plot of Regression -----------------------------
plot(x,y,'x', x, sigma);
title('Regression')
xlabel('Temp (Degrees Fahrenheit)')
ylabel('Pass or Fail (1 or 0)')
end