def test_cube(): XX = [] size = 10 for i in range(0, size): for j in range(0, size): for k in range(0, size): XX.append([i, j, k]) XX = np.array(XX) # for i, x in enumerate(XX): # print (i, x) dr = DRUHG(algorithm='slow', max_ranking=200, verbose=False) dr.fit(XX) s = 2 * len(XX) - 2 print(dr.mst_) # assert (0==1) labels = dr.labels_ n_clusters = len(set(labels)) - int(-1 in labels) print('n_clusters', n_clusters) print('labels', labels) assert (n_clusters == 1 + 6) # labels = dr.relabel(limit1=1) labels = dr.relabel(limit1=1, limit2=len(XX)) print('out') n_clusters = len(set(labels)) - int(-1 in labels) print('n_clusters2', n_clusters) print('labels2', labels) assert (n_clusters == 1 + 6 + 12)
def test_iris(): iris = datasets.load_iris() XX = iris['data'] # print (XX, type(XX)) dr = DRUHG(max_ranking=50, verbose=False) dr.fit(XX) labels = dr.labels_ ari = adjusted_rand_score(iris['target'], labels) print('iris ari', ari) assert (ari >= 0.50) # breaking biggest cluster labels = dr.relabel(limit1=0, limit2=int(len(XX) / 2), fix_outliers=1) ari = adjusted_rand_score(iris['target'], labels) print('iris ari', ari) assert (ari >= 0.85)