# ---- start your code ---- #
    pass
    """
    fill the array allSamples to hold the samples, each sample
    takes two attributes of an iris instance
    """
    for line in data:
        content = line.strip().split(",")
        d = sample.Sample('', [float(content[1]), float(content[3])])
        allSamples.append(d)
    # ---- end of your code --- #

    verbose = False
    k = 3
    print("before clustering")
    unclustered = [kmeans.Cluster(allSamples)]
    util.plot_cluster(unclustered)

    clusters = unclustered
    print("after clustering")
    # IMPLEMENTATION: apply k means to cluster the samples
    # ---- start your code ---- #
    pass
    clusters = kmeans.kmeans(allSamples, 3, verbose)

    # ---- end of your code --- #

    util.plot_cluster(clusters, verbose)
    """ bonus """
    normalized_allSamples = allSamples
    print("after normalizing")
Example #2
0
 def test_cluster_can_compare_with_mean(self):
     c = kmeans.Cluster(p(1, 1))
     self.assertTrue(c.same_mean(p(1, 1)))
     self.assertFalse(c.same_mean(p(1, 2)))
Example #3
0
 def test_cluster_can_compute_mean_vector(self):
     c = kmeans.Cluster(p(1, 1))
     c.add(p(1, 1))
     c.add(p(1.5, 2))
     c.add(p(3, 4))
     self.assertEquals(p(1.8, 2.3), c.mean_vector())
Example #4
0
 def test_point_can_be_added_to_cluster(self):
     c = kmeans.Cluster(p(1, 1))
     c.add(p(2, 2))
     self.assertEquals(p(2, 2), c.points[0])