You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

predict.m 1.2 kB

8 years ago
12345678910111213141516171819202122232425262728293031323334353637
  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. X = [ones(m,1), X];
  11. % ====================== YOUR CODE HERE ======================
  12. % Instructions: Complete the following code to make predictions using
  13. % your learned neural network. You should set p to a
  14. % vector containing labels between 1 to num_labels.
  15. %
  16. % Hint: The max function might come in useful. In particular, the max
  17. % function can also return the index of the max element, for more
  18. % information see 'help max'. If your examples are in rows, then, you
  19. % can use max(A, [], 2) to obtain the max for each row.
  20. %
  21. a2 = sigmoid(X * Theta1');
  22. a2 = [ones(size(a2,1), 1), a2];
  23. p = sigmoid(a2 *Theta2');
  24. [temp_p,p] = max(p, [], 2);
  25. % =========================================================================
  26. end

机器学习

Contributors (1)