Created
April 20, 2020 06:29
-
-
Save theptrk/875379cc34de64925007ec99831641df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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