How do I find which cluster my data belongs to using Python?

后端 未结 2 1926
谎友^
谎友^ 2021-01-27 05:21

I just ran PCA and then K-means Clustering algorithm on my data, after running the algorithm I get 3 clusters. I am trying to figure out which clusters my input belongs to , in

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 06:03

    To group instances by their assigned cluster id

    N_CLUSTERS = 3
    clusters = [x_10d[X_clustered == i] for i in range(N_CLUSTERS)]
    # replace x_10d with where you want to retrieve data
    
    # to have a look
    for i, c in enumerate(clusters):
        print('Cluster {} has {} members: {}...'.format(i, len(c), c[0]))
    
    # which prints
    # Cluster 0 has 37 members: [0.95690664 0.07578273 0.0094432 ]...
    # Cluster 1 has 30 members: [0.03124354 0.97932615 0.47270528]...
    # Cluster 2 has 33 members: [0.26331688 0.5039502  0.72568873]...
    

提交回复
热议问题