Supervised Learning
LOGISTIC REGRESSION |
% Logistic Regression
clc, close all
N = 100; n = 5;
x = sort( randn(N,1));
X = [x ones(N,1)];
theta = [3.5 2]'; % Column Vector
y = ( fsigmoid( theta'*X' ) ); y = y >= .5;
IDX = unidrnd( N, 1, n);
y( IDX) = mod( y( IDX)+1,2);
plot(x, y, '+r','linewidth', 2), hold on
% STOCHASTIC ASCENT RULE
thetahat = [ 0 0]';
theta = 1+thetahat; k = 1; MAXITER = 100;
alpha = .1;
while( norm(theta - thetahat) > 1e-3 && k < MAXITER)
theta = thetahat;
for j = 1:2
for i = 1:N
thetahat(j) = thetahat(j) + alpha*...
( y(i)- fsigmoid(thetahat'*X(i,:)' ) )*X(i,j);
end
end
k = k + 1;
h = fsigmoid(thetahat'*X');
plot(x, h, '--', 'linewidth', 1)
end
axis tight, xlabel('x'), ylabel('y'), title('Logistic Regression'), grid
%%%%% Logistic Regression
function gz = fsigmoid( z)
gz = 1./(1+exp(-z));
No hay comentarios:
Publicar un comentario