kmeans.py
def generate_k(data_set, k):
    """
    Given `data_set`, which is an array of arrays,
    find the minimum and maximum for each coordinate, a range.
    Generate `k` random points between the ranges.
    Return an array of the random points within the ranges.
    """
    centers = []
    dimensions = len(data_set[0])
    min_max = defaultdict(int)

    for point in data_set:
        for i in xrange(dimensions):
            val = point[i]
            min_key = 'min_%d' % i
            max_key = 'max_%d' % i
            if min_key not in min_max or val < min_max[min_key]:
                min_max[min_key] = val
            if max_key not in min_max or val > min_max[max_key]:
                min_max[max_key] = val

    for _k in xrange(k):
        rand_point = []
        for i in xrange(dimensions):
            min_val = min_max['min_%d' % i]
            max_val = min_max['max_%d' % i]

            rand_point.append(uniform(min_val, max_val))

        centers.append(rand_point)

    return centers

    Given `data_set`, which is an array of arrays,
    find the minimum and maximum for each coordinate, a range.
    Generate `k` random points between the ranges.
    Return an array of the random points within the ranges.
    
Given `data_set`, which is an array of arrays,
find the minimum and maximum for each coordinate, a range.
Generate `k` random points between the ranges.
Return an array of the random points within the ranges.
Given ` data_set ` which is an array of arrays find the minimum and maximum for each coordinate a range . Generate ` k ` random points between the ranges . Return an array of the random points within the ranges .
def generate_k(data_set, k):
    centers = []
    dimensions = len(data_set[0])
    min_max = defaultdict(int)
    for point in data_set:
        for i in xrange(dimensions):
            val = point[i]
            min_key = 'min_%d' % i
            max_key = 'max_%d' % i
            if min_key not in min_max or val < min_max[min_key]:
                min_max[min_key] = val
            if max_key not in min_max or val > min_max[max_key]:
                min_max[max_key] = val
    for _k in xrange(k):
        rand_point = []
        for i in xrange(dimensions):
            min_val = min_max['min_%d' % i]
            max_val = min_max['max_%d' % i]
            rand_point.append(uniform(min_val, max_val))
        centers.append(rand_point)
    return centers
def generate_k ( data_set , k ) : centers = [ ] dimensions = len ( data_set [ 0 ] ) min_max = defaultdict ( int ) for point in data_set : for i in xrange ( dimensions ) : val = point [ i ] min_key = 'min_%d' % i max_key = 'max_%d' % i if min_key not in min_max or val < min_max [ min_key ] : min_max [ min_key ] = val if max_key not in min_max or val > min_max [ max_key ] : min_max [ max_key ] = val for _k in xrange ( k ) : rand_point = [ ] for i in xrange ( dimensions ) : min_val = min_max [ 'min_%d' % i ] max_val = min_max [ 'max_%d' % i ] rand_point . append ( uniform ( min_val , max_val ) ) centers . append ( rand_point ) return centers
Given `data_set`, which is an array of arrays,
find the minimum and maximum for each coordinate, a range.
Given ` data_set ` which is an array of arrays find the minimum and maximum for each coordinate a range .
"""
    Given `data_set`, which is an array of arrays,
    find the minimum and maximum for each coordinate, a range.
    Generate `k` random points between the ranges.
    Return an array of the random points within the ranges.
    """
data_set
k