Cursera: machine learning ex7.

This commit is contained in:
Vahagn Khachatryan
2015-03-30 12:17:51 +04:00
parent 29c396874e
commit ed6828bf1a
22 changed files with 1401 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
function [U, S] = pca(X)
%PCA Run principal component analysis on the dataset X
% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X
% Returns the eigenvectors U, the eigenvalues (on diagonal) in S
%
% Useful values
[m, n] = size(X);
% You need to return the following variables correctly.
U = zeros(n);
S = zeros(n);
% ====================== YOUR CODE HERE ======================
% Instructions: You should first compute the covariance matrix. Then, you
% should use the "svd" function to compute the eigenvectors
% and eigenvalues of the covariance matrix.
%
% Note: When computing the covariance matrix, remember to divide by m (the
% number of examples).
%
M = X'*X / m;
[U S x ] = svd(M);
% =========================================================================
end