1
0
Fork 0

Find closest centroids

master
neingeist 10 years ago
parent 229023b69c
commit f8c0087ff3

@ -21,11 +21,20 @@ idx = zeros(size(X,1), 1);
% Note: You can use a for-loop over the examples to compute this. % Note: You can use a for-loop over the examples to compute this.
% %
for i = 1:size(X,1)
idx(i) = 0; % unassigned yet
best_distance = Inf;
for k = 1:K
distance = norm(X(i,:) - centroids(k,:))^2;
if distance < best_distance
idx(i) = k;
best_distance = distance;
end
end
end
% ============================================================= % =============================================================