Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 3/Programming Assignment - 2/machine-learning-ex2/ex2/predict.m
863 views
1
function p = predict(theta, X)
2
%PREDICT Predict whether the label is 0 or 1 using learned logistic
3
%regression parameters theta
4
% p = PREDICT(theta, X) computes the predictions for X using a
5
% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)
6
7
m = size(X, 1); % Number of training examples
8
9
% You need to return the following variables correctly
10
p = zeros(m, 1);
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Complete the following code to make predictions using
14
% your learned logistic regression parameters.
15
% You should set p to a vector of 0's and 1's
16
%
17
18
g = sigmoid(X*theta);
19
for i = 1:size(X,1), if(g(i,1)>=0.5) p(i,1) = 1; end; end;
20
disp(p);
21
% =========================================================================
22
23
24
end
25
26