function a
alpha = 0.0001;
[m,n] = size(q1x); max_iters = 500; X = [ones(size(q1x,1),1), q1x]; % append col of ones for intercept term theta = zeros(n+1, 1); % initialize theta
for k = 1:max_iters
hx = 1./(1+exp(-X*theta));
theta = theta + alpha * X' * (q1y-hx);
ll(k) = sum(q1y .* log(hx) + (1 - q1y) .* log(1 - hx) );
hold on;
end
plot(q1x(1:50,1),q1x(1:50,2),'o');
hold on;
plot(q1x(51:99,1),q1x(51:99,2),'r*');
hold on;
x1=0:0.01:8;
y=(1-theta(1,1))/theta(3,1)-x1*theta(2,1)/theta(3,1);
plot(x1,y)
q1x.dat,q1y.dat:http://cs229.stanford.edu/
版权声明:本文为博主原创文章,未经博主允许不得转载。