Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 8/Programming Assignment - 7/ex7/kMeansInitCentroids.m
863 views
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
8
% You should return this values correctly
9
centroids = zeros(K, size(X, 2));
10
11
% ====================== YOUR CODE HERE ======================
12
% Instructions: You should set centroids to randomly chosen examples from
13
% the dataset X
14
%
15
randidx = randperm(size(X, 1));
16
centroids = X(randidx(1:K), :);
17
% =============================================================
18
19
end
20
21
22