Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 8/Programming Assignment - 7/ex7/projectData.m
863 views
1
function Z = projectData(X, U, K)
2
%PROJECTDATA Computes the reduced data representation when projecting only
3
%on to the top k eigenvectors
4
% Z = projectData(X, U, K) computes the projection of
5
% the normalized inputs X into the reduced dimensional space spanned by
6
% the first K columns of U. It returns the projected examples in Z.
7
%
8
9
% You need to return the following variables correctly.
10
Z = zeros(size(X, 1), K);
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Compute the projection of the data using only the top K
14
% eigenvectors in U (first K columns).
15
% For the i-th example X(i,:), the projection on to the k-th
16
% eigenvector is given as follows:
17
% x = X(i, :)';
18
% projection_k = x' * U(:, k);
19
%
20
U_reduce = U(:,[1:K]);
21
Z = X * U_reduce;
22
% =============================================================
23
24
end
25
26