title: How to initialize centroids in "k-means clustering" belonging to the domain of the data points?
body: <p>How can I modify this code to initialize the centroids within the domain of the datapoints taken ?</p>
  
  <p>For ex: if DATA = [[2.0, 5.0], [1.0, 5.0], [22.0, 55.0], [42.0, 12.0], [15.0, 16.0]]
  Then centroids(x,y) could be any value such that x belong to :[1,42] and y belongs to : [5,55].
  The centroids should not necessarily be datapoints.</p>
  
  <p>Note: The dataype for data is float.</p>
  
  <pre><code>import random
  import math
  
  BIG_NUMBER = math.pow(10, 10)
  data = []
  centroids = []
  
  class Centroid:
  def __init__(self, x, y):
      self.x = x
      self.y = y
  
  def set_x(self, x):
      self.x = x
  
  def get_x(self):
      return self.x
  
  def set_y(self, y):
      self.y = y
  
  def get_y(self):
      return self.y
  
  def initialize_centroids(k,DATA):
  for j in range(k):
      x = random.choice(DATA)
      centroids.append(Centroid(x[0], x[1]))
  
  return
  </code></pre>