predict.m 585 B

1234567891011121314151617181920
  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. % Useful values
  6. m = size(X, 1);
  7. num_labels = size(Theta2, 1);
  8. % You need to return the following variables correctly
  9. p = zeros(size(X, 1), 1);
  10. h1 = sigmoid([ones(m, 1) X] * Theta1');
  11. h2 = sigmoid([ones(m, 1) h1] * Theta2');
  12. [dummy, p] = max(h2, [], 2);
  13. % =========================================================================
  14. end