Last active
April 9, 2021 03:36
-
-
Save rlopc/8094962 to your computer and use it in GitHub Desktop.
Compute sigmoid function, the hypothesis function in Logistic Regression
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
function g = sigmoidFunction(z) | |
% Compute sigmoid function | |
% You need to return the following variables correctly | |
g = zeros(size(z)); | |
% Instructions: z can be a matrix, vector or scalar | |
g = 1.0 ./ ( 1.0 + exp(-z)); % For Matlab | |
% g = 1.0 ./ ( 1.0 + e.^(-z)); % For Octave, it can use 'exp(1)' or 'e' | |
end |
It allows you to catch the number of elements whether its a matrix/vector/scalar, and apply properly the elementwize option.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain the use of g = zeros(size(z));
I am not able to get how to use it