【问题标题】:dealing with noise in hdbscan处理 hdbscan 中的噪声
【发布时间】:2019-12-20 01:21:36
【问题描述】:

我一直在使用 (x,y) 点“point_coord”的小实例测试 scikit learn 包中的 hdbscan,而生成的集群对我来说真的没有意义。鉴于样本量小,我允许单个集群。

我希望有两个集群:第 4 点和第 5 点聚集在一起,而其余点则聚集在一起。

point_coord=[[0,0],[1,1],[0,1],[50,40],[50,45],[2,3],[1,2]]

test=pairwise_distances(point_coord)

clusterer= hdbscan.HDBSCAN( allow_single_cluster=True,                
metric='precomputed')

clusterer.fit(test)

但是,生成的 clusterer.labels 是:

[-1, 0, 0, 0, -1, 0, 0]

【问题讨论】:

    标签: noise hdbscan


    【解决方案1】:

    您需要考虑的事项很少:

    1 - HDBSCAN 是一种噪声感知聚类算法。因此,输出中的 -1 结果是被视为异常值并从聚类中排除的数据。 从 Documentation

    重要的是,HDBSCAN 具有噪声感知能力——它具有数据样本的概念 没有分配给任何集群。这是通过分配来处理的 这些样本标签 -1

    2 - 数据集非常小,未设置 min_samplesmin_cluster_size 参数。因此 HDBSCAN 使用默认参数,将最小集群大小设置为 5。您可以在 clusterer.fit(distance_matrix) 命令的输出中查看使用的参数。

    HDBSCAN(algorithm='best', allow_single_cluster=False, alpha=1.0,
            approx_min_span_tree=True, cluster_selection_method='eom',
            core_dist_n_jobs=4, gen_min_span_tree=False, leaf_size=40,
            match_reference_implementation=False, memory=Memory(location=None),
            metric='precomputed', min_cluster_size=5, min_samples=None, p=None,
            prediction_data=False) 
    

    请参阅文档(Parameter Selection for HDBSCAN) 了解如何正确配置算法。

    这是您的代码的更正版本,带有集群树状图。

    point_coord=[[0,0],[1,1],[0,1],[50,40],[50,45],[2,3],[1,2]]
    distance_matrix=pairwise_distances(point_coord)
    clusterer= hdbscan.HDBSCAN(metric='precomputed', min_samples=1,min_cluster_size=2)
    clusterer.fit(distance_matrix)
    print(clusterer.labels_)
    clusterer.single_linkage_tree_.plot()
    

    输出:

    【讨论】:

      【解决方案2】:

      你可以试试:

      from sklearn.cluster import KMeans
      import numpy as np
      X = np.array(point_coord)
      kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
      kmeans.labels_
      

      输出:array([1,1,1,0,0,1,1])

      我同意它应该是这样的: (0, 0, 0, 1, 1, 0, 0)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-06
        • 1970-01-01
        • 2018-08-04
        • 2018-04-14
        • 2020-06-06
        • 2021-12-26
        • 2022-01-26
        • 2017-11-04
        相关资源
        最近更新 更多