kMeansInitCentroids <- function(X, K) { # 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 <- matrix(0, K, dim(X)[2]) # ========================= YOUR CODE HERE ======================= # Instructions: You should set centroids to randomly chosen examples from # the dataset X. # # Hint: You can randomly reorder the indices of examples and then # take the first K. Have a look at the function 'sample'. # ================================================================= return(centroids) }