|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
function centroids = kMeansInitCentroids(X, K)
|
|
|
|
|
%KMEANSINITCENTROIDS This function initializes K centroids that are to be
|
|
|
|
|
%KMEANSINITCENTROIDS This function initializes K centroids that are to be
|
|
|
|
|
%used in K-Means on the dataset X
|
|
|
|
|
% centroids = KMEANSINITCENTROIDS(X, K) returns K initial centroids to be
|
|
|
|
|
% used with the K-Means on the dataset X
|
|
|
|
@ -13,12 +13,10 @@ centroids = zeros(K, size(X, 2));
|
|
|
|
|
% the dataset X
|
|
|
|
|
%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
% Randomly reorder the indices of examples
|
|
|
|
|
randidx = randperm(size(X, 1));
|
|
|
|
|
% Take the first K examples as centroids
|
|
|
|
|
centroids = X(randidx(1:K), :);
|
|
|
|
|
|
|
|
|
|
% =============================================================
|
|
|
|
|
|
|
|
|
|