def check_kmeans2_simple(self, level=1): """Testing simple call to kmeans2 and its results.""" initc = N.concatenate(([[X[0]], [X[1]], [X[2]]])) code = initc.copy() code1 = kmeans2(X, code, iter = 1)[0] code2 = kmeans2(X, code, iter = 2)[0] assert_array_almost_equal(code1, CODET1) assert_array_almost_equal(code2, CODET2)
def check_kmeans2_rank1(self, level=1): """Testing simple call to kmeans2 with rank 1 data.""" data = N.fromfile(open(DATAFILE1), sep = ", ") data = data.reshape((200, 2)) data1 = data[:, 0] data2 = data[:, 1] initc = data1[:3] code = initc.copy() code1 = kmeans2(data1, code, iter = 1)[0] code2 = kmeans2(data1, code, iter = 2)[0]
def check_kmeans_lost_cluster(self, level=1): """This will cause kmean to have a cluster with no points.""" data = N.fromfile(open(DATAFILE1), sep = ", ") data = data.reshape((200, 2)) initk = N.array([[-1.8127404, -0.67128041], [ 2.04621601, 0.07401111], [-2.31149087,-0.05160469]]) res = kmeans(data, initk) res = kmeans2(data, initk, missing = 'warn') try : res = kmeans2(data, initk, missing = 'raise') raise AssertionError("Exception not raised ! Should not happen") except ClusterError, e: print "exception raised as expected: " + str(e)
def check_kmeans2_init(self, level = 1): """Testing that kmeans2 init methods work.""" data = N.fromfile(open(DATAFILE1), sep = ", ") data = data.reshape((200, 2)) kmeans2(data, 3, minit = 'random') kmeans2(data, 3, minit = 'points') # Check special case 1d data = data[:, :1] kmeans2(data, 3, minit = 'random') kmeans2(data, 3, minit = 'points')