MATLAB (5): The model is used to predict/calculate the accuracy of the model after the θ value is obtained

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.