Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Get similarity matrix all_cc, which is a list of list, where all_cc[i][j] is the correlation coefficient between data i and j. It is an upper trangular matrix.
- ...
- #to use hierarchy module, condensed distance matrix should be available.
- nmodel=10000
- q=lambda i,j,n: i*n+j-i*(i+1)/2-i-1
- condensed_cc=[0]*int(nmodel*(nmodel-1)/2)
- for i in range(nmodel-1):
- for j in range(i+1,nmodel):
- index=int(q(i,j,nmodel)):
- condensed_cc[index]=all_cc[i][j]
- numpy.save("cc10000",condensed_cc)
- condensed_cc=numpy.load("condensed_cc")
- #get condensed distance matrix using formula distance=1-c.c.
- condensed_dist=1-condensed_cc
- #cluster
- z=linkage(condensed_dist, 'average', 'correlation')
- nc=500 #number of groups
- f=fcluster(z,nc,'maxclust')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement