I have a distance matrix presents the distance matrix for pairwise elements
such as
A B C D .....
A n1 n2 n3
B n1
C n2 n4
D n3 n5 .......
E.........
i input the array like for clustering
arry= [ 0 n1, n2, n3..
n1.......
n2 n4
n3 n5 ]
Y=sch.linkage(arry,'single')
cutoff=1e-6
T=sch.fcluster(Y, cutoff,'distance')
print T
Z=sch.dendrogram(Y, color_threshold=cutoff)
my fcluster output is like
[ 4 10 12 1 5 13 2 11 1 7 8 3 14 6 10 16 9 15 1 7]
from a previous poster of others
Clustering with scipy – clusters via distance matrix, how to get back the original objects
I understand
the output T[i] only presents the number of element in a cluster ..how I link the original element A, B ,C ,D ,E….. elements with the cluster result and the dendrogram? and lab them properly into my figures.
“I understand the output T[i] only presents the number of element in a cluster…”
T[j]is the “cluster number” of the j-th data point. That is,fclusterprovides the assignments of data points to clusters. So, for example, if there are five data points, andfclusterputs the first, second and last in cluster 1 and the others in cluster 2, the return value offclusterwill bearray([1, 1, 2, 2, 1]).Here’s a demo that shows how you can pull that data apart. For convenience, I’ve used
fclusterdatainstead of the combination oflinkageandfcluster.fclusterdatareturns the same thing asfcluster.Typical output: