Using model to predict/calculate the accuracy of the model after the θ value is obtained
Percent ============== part 4:predict and accuracies ==============
% After learning the parameters, you'll like to use it to predict the outcomes
% on unseen data. You'll use the logistic regression model
% to predict the probability, a student with score , on exam 1 and
% score in exam 2 would be admitted.
%
% Furthermore, you'll compute the training and test set accuracies of
% our model.
%
% Your Task is to total the code in PREDICT.M
% Predict probability for a student with score-on exam 1
% and score-on exam 2
Prob = Sigmoid ([1] * theta);
fprintf ([' for a student with scores, we predict an admission ' ...
' Probability of%f\n\n '], prob);
% Compute accuracy on our training set
p = Predict (theta, X);
fprintf (' Train accuracy:%f\n ', mean (double (p = = y)) * 100);
fprintf (' \nprogram paused. Press ENTER to continue.\n ');
Pause
Predict.m
function P = Predict (theta, X)
%predict PREDICT Whether the label is 0 or 1 using learned logistic
%regression Parameters Theta
% P = PREDICT (theta, X) computes the predictions for X using a
% threshold at 0.5 (i.e., if sigmoid (Theta ' *x) >= 0.5, predict 1)
m = Size (X, 1); % Number of training examples
% need to return the following variables correctly
p = Zeros (M, 1);
% ====================== YOUR CODE here ======================
% Instructions:complete The following code to make predictions using
% your learned logistic regression parameters.
% should set p to a vector of 0 ' s and 1 ' s
%
For i=1:m
If Sigmoid (X (i,:) * theta) >=0.5
P (i) = 1;
Else
P (i) = 0;
End
End
% =========================================================================
End
MATLAB (5): The model is used to predict/calculate the accuracy of the model after the θ value is obtained