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.

pca.m 853 B

8 years ago
1234567891011121314151617181920212223242526272829303132
  1. function [U, S] = pca(X)
  2. %PCA Run principal component analysis on the dataset X
  3. % [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X
  4. % Returns the eigenvectors U, the eigenvalues (on diagonal) in S
  5. %
  6. % Useful values
  7. [m, n] = size(X);
  8. % You need to return the following variables correctly.
  9. U = zeros(n);
  10. S = zeros(n);
  11. % ====================== YOUR CODE HERE ======================
  12. % Instructions: You should first compute the covariance matrix. Then, you
  13. % should use the "svd" function to compute the eigenvectors
  14. % and eigenvalues of the covariance matrix.
  15. %
  16. % Note: When computing the covariance matrix, remember to divide by m (the
  17. % number of examples).
  18. %
  19. U = X' * X / m;
  20. % [U,S,V]
  21. [U,S,V] = svd(U);
  22. % =========================================================================
  23. end

机器学习

Contributors (1)