How to get non-singleton cluster ids in scipy hierachical clustering

后端 未结 1 1162
遥遥无期
遥遥无期 2021-01-17 02:11

According to this we can get labels for non-singleton clusters.

I tried this with a simple example.

import numpy as np
import scipy.cluster.hierarchy         


        
相关标签:
1条回答
  • 2021-01-17 02:21

    I think the document is not very clear at this part and the sample code in it is not even operational. But it is clear that 1 means the 2nd observation and (3) means there are 3 observation in that node.

    If you want to know what are the 3 obs. in the 2nd node, if that is your question:

    In [51]:
    D4=dendrogram(linkage_matrix,
                  color_threshold=1,
                  p=4,
                  truncate_mode='lastp',
                  distance_sort='ascending')
    D7=dendrogram(linkage_matrix,
                  color_list=['g',]*7,
                  p=7,
                  truncate_mode='lastp',
                  distance_sort='ascending', no_plot=True)  
    from itertools import groupby
    [list(group) for key, group in groupby(D7['ivl'],lambda x: x in D4['ivl'])]
    Out[51]:
    [['1'], ['6', '0', '3'], ['2'], ['4', '5']]
    

    The 2nd node contains obs. 7th, 1th and 4th, and the 2th node contains the 5th and the 6th observations.

    0 讨论(0)
提交回复
热议问题