Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function centroids = kMeansInitCentroids(X, K)
% initialize placeholder
centroids = zeros(K, size(X, 2));
% use randperm to shuffle the row indices of X
shuffle_X = randperm(size(X,1));
% only use the first K number of shuffled indices
first_K = shuffle_X(1:K, :);
for i=1:K
centroids(i, :) = X(i, :);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment