Skip to content

Instantly share code, notes, and snippets.

@AndyMoreland
Created October 12, 2014 06:21
Show Gist options
  • Save AndyMoreland/eb576b10b58e12945d14 to your computer and use it in GitHub Desktop.
Save AndyMoreland/eb576b10b58e12945d14 to your computer and use it in GitHub Desktop.
load ~/Downloads/q1x.dat
load ~/Downloads/q1y.dat
hold off
%scatter(q1x, q1y)
hold on
X = [ones(length(q1x), 1), q1x];
Y = q1y;
theta = zeros(size(X, 2), 1)
iterations = 20
for i = 1:iterations
h = sigmoid(-1 * X * theta);
grad = (Y - h)' * X;
hessian = zeros(3, 3);
for j = 1:length(X)
feature_vec = X(j,:);
h = sigmoid(-1 * feature_vec * theta);
hessian = hessian - feature_vec' * feature_vec * (h) * (1-h);
end
theta = theta - inv(hessian) * grad'
end
hold on
positive = (Y == 1);
negative = (Y == 0);
x_vals = q1x(:,1);
y_vals = q1x(:,2);
scatter(x_vals(positive),y_vals(positive),100,'o');
scatter(x_vals(negative),y_vals(negative),100,'x');
dbx=[0:0.1:8];
dby=(-theta(1)-theta(2)*dbx)/theta(3);
plot(dbx,dby);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment