def linkage(self, D): ''' linkage matrix with derivative node n+i''' import scipy.cluster.hierarchy as sch Y = sch.median(D) #Z = sch.to_tree(Y, rd=True) N = D.shape[0] Y = concatenate((Y, arange(N,2*N-1).reshape((Y.shape[0], 1))), 1) return Y
def dendrogram(D, link): ''' Plot dendrogram of cluster's parity.''' import scipy.cluster.hierarchy as sch lbl = [str(n+1) for n in xrange(D.shape[0])] # Compute and plot dendrogram. fig = plt.figure(figsize=(8,14),dpi=80) ax1 = fig.add_axes([0.04,0.04,0.9,0.9]) Y = sch.median(D) Z1 = sch.dendrogram(Y, orientation='right',labels=lbl) ax1.set_xticks([]) ax1.set_ylabel("Identified Cluster") ax1.set_xlabel("Cluster Parity") plt.title(link) #plt.show() plt.savefig(pathjoin("TESTS",link,"plots",'dendrogram_'+link+'.png'),format='png', dpi=100) #plt.show() plt.close("all")