Created
March 12, 2015 12:53
-
-
Save s-trooper/9677d94537ddaae4bb25 to your computer and use it in GitHub Desktop.
ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = inputs | |
y = output | |
m = length(y); | |
theta = initial_theta = 0; | |
sigmoid(z) = 1.0 ./ (1.0 + e.^-z); | |
h = sigmoid(X * theta); | |
% gradient descent, here we go find theta ... | |
alpha = 0.001; | |
num_iters = 1000000; | |
for iter = 1:num_iters | |
gradient = X' * (h - y) / m; | |
theta = theta - alpha * gradient; | |
end | |
% cost function to check the hypothesis ... should always decreasing | |
cost = (-y' * log(h) - (1 - y)' * log(1 - h)) / m; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment