ex7.m
Part 1: Find Closest Centroids
-
Go over every example, find its closest centroid, and store the index inside idx at the appropriate location
1 | for i = 1: size(X,1) % query from 1 to 300 |
Part 2: Compute Means
-
Go over every centroid and compute mean of all points that belong to it
1 | for i = 1 : K |
ex7 pca.m
Part 2: Principal Component Analysis
-
You should first compute the covariance matrix. Then, you should use the “svd” function to compute the eigenvectors and eigenvalues of the covariance matrix
1 | % compute sigma |
Part 3: Dimension Reduction
-
Compute the projection of the data using only the top K eigenvectors in U (first K columns)
1 | % using only the top K eigenvectors in U |
-
Compute the approximation of the data by projecting back onto the original space using the top K eigenvectors in U
1 | % implementing PCA |