| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- function p = predict(Theta1, Theta2, X)
- %PREDICT Predict the label of an input given a trained neural network
- % p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the
- % trained weights of a neural network (Theta1, Theta2)
- % Useful values
- m = size(X, 1);
- num_labels = size(Theta2, 1);
- % You need to return the following variables correctly
- p = zeros(size(X, 1), 1);
- % ====================== YOUR CODE HERE ======================
- % Instructions: Complete the following code to make predictions using
- % your learned neural network. You should set p to a
- % vector containing labels between 1 to num_labels.
- %
- % Hint: The max function might come in useful. In particular, the max
- % function can also return the index of the max element, for more
- % information see 'help max'. If your examples are in rows, then, you
- % can use max(A, [], 2) to obtain the max for each row.
- %
- X1 = [ones(rows(X), 1) X];
- a2 = sigmoid(X1 * Theta1');
- a2_1 = [ones(rows(a2), 1) a2];
- % size = 5000 * 26
- %size(a2_1)
- a3 = sigmoid(a2_1 * Theta2');
- % size = 5000 * 10
- %size(a3)
- # pick the max value at each row
- [v,p] = max(a3, [], 2);
- # check to see that the array contain values that are mapped to the 10 classes
- #unique(p)
- % =========================================================================
- end
|