Ng机器学习 Week8 Unsupervised Learning

Clustering

Ng机器学习 Week8 Unsupervised Learning_第1张图片
Ng机器学习 Week8 Unsupervised Learning_第2张图片
Ng机器学习 Week8 Unsupervised Learning_第3张图片

Principal Component Analysis


Ng机器学习 Week8 Unsupervised Learning_第4张图片 Q2选2。。。手滑

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 examples
randidx = randperm(size(X, 1));
% Take the first K examples as centroids
centroids = 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)'; 

你可能感兴趣的:(Ng机器学习 Week8 Unsupervised Learning)