You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
function centroids = kMeansInitCentroids(X, K)
|
|
|
|
%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
|
|
|
|
%
|
|
|
|
|
|
|
|
% You should return this values correctly
|
|
|
|
centroids = zeros(K, size(X, 2));
|
|
|
|
|
|
|
|
% ====================== YOUR CODE HERE ======================
|
|
|
|
% Instructions: You should set centroids to randomly chosen examples from
|
|
|
|
% 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), :);
|
|
|
|
|
|
|
|
% =============================================================
|
|
|
|
|
|
|
|
end
|
|
|
|
|