机器学习|吴恩达机器学习作业7

pca

sigma = X' * X / m; [U,S,V] = svd(sigma);

机器学习|吴恩达机器学习作业7
文章图片

projectData
U_reduce = U(:,1:K); Z = X * U_reduce;

【机器学习|吴恩达机器学习作业7】机器学习|吴恩达机器学习作业7
文章图片

recoverData
U_reduce = U(:,1:K); X_rec = Z * U_reduce';

机器学习|吴恩达机器学习作业7
文章图片

findClosestCentroids
m = size(X,1); for i = 1:m ind_k = zeros(K,1); for j = 1:K ind_k(j) = sum((X(i,:) - centroids(j,:)) .^ 2); endfor [value,index] = min(ind_k); idx(i) = index; endfor

机器学习|吴恩达机器学习作业7
文章图片

computeCentroids
for i = 1:K centroids(i,:) = ((idx == i)' * X) / sum(idx == i); endfor

机器学习|吴恩达机器学习作业7
文章图片

    推荐阅读