You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

kMeansInitCentroids.m 750 B

8 years ago
12345678910111213141516171819202122232425
  1. function centroids = kMeansInitCentroids(X, K)
  2. %KMEANSINITCENTROIDS This function initializes K centroids that are to be
  3. %used in K-Means on the dataset X
  4. % centroids = KMEANSINITCENTROIDS(X, K) returns K initial centroids to be
  5. % used with the K-Means on the dataset X
  6. %
  7. % You should return this values correctly
  8. centroids = zeros(K, size(X, 2));
  9. % ====================== YOUR CODE HERE ======================
  10. % Instructions: You should set centroids to randomly chosen examples from
  11. % the dataset X
  12. %
  13. % for i = 1 : K
  14. % centroids(i,:) = X(i,:);
  15. % end
  16. randidx = randperm(size(X, 1));
  17. % Take the first K examples as centroids
  18. centroids = X(randidx(1:K), :);
  19. % =============================================================
  20. end

机器学习

Contributors (1)