Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 5/Programming Assignment - 4/machine-learning-ex4/ex4/predict.m
864 views
1
function p = predict(Theta1, Theta2, X)
2
%PREDICT Predict the label of an input given a trained neural network
3
% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the
4
% trained weights of a neural network (Theta1, Theta2)
5
6
% Useful values
7
m = size(X, 1);
8
num_labels = size(Theta2, 1);
9
10
% You need to return the following variables correctly
11
p = zeros(size(X, 1), 1);
12
13
h1 = sigmoid([ones(m, 1) X] * Theta1');
14
h2 = sigmoid([ones(m, 1) h1] * Theta2');
15
[dummy, p] = max(h2, [], 2);
16
17
% =========================================================================
18
19
20
end
21
22