Ng机器学习 Week8 Unsupervised Learning

来源:互联网 发布:守护进程 windows 编辑:程序博客网 时间:2024/06/05 06:18

Clustering

Q1&Q2
Q3&Q4
Q5

Principal Component Analysis

Q1
Q2&Q3 Q2选2。。。手滑
Q4&Q5

Quiz

findClosestCentroids.m

temp = zeros(K,1); for i = 1:size(X,1)    for j = 1:K        temp(j) = sum((X(i,:) - centroids(j,:)).^2);     end   [value,idx(i)] = min(temp,[],1); end 

computeCentroids.m

for i = 1:K    centroids(i,:) = (X' * (idx == i)) / sum(idx == i);   %X' * (idx == i)  To add x in same center end 

kMeansInitCentroids.m

% Randomly reorder the indices of examplesrandidx = randperm(size(X, 1));% Take the first K examples as centroidscentroids = X(randidx(1:K), :);

pca.m

sigma = X' * X / m;     % compute the covariance matrix[U,S,V] = svd(sigma);   % SVD

projectData.m

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

recoverData.m

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