【问题标题】:Clustering evaluation with a manually labeled ground-truth使用手动标记的真实值进行聚类评估
【发布时间】:2020-08-27 05:25:36
【问题描述】:

我正在使用不同方法(Kmeans、HAC 和 LDA)进行文档聚类。

现在我已经对我的文档进行了一些手动聚类,以检查我所说的必须放在一起的文档是否以及有多少实际上放在一起。

聚类的输出(对于所有方法)是标准的,是 CSV,格式为:

聚类输出

id    label
 0        1
 1        4
 2        0
     ...
 N        1

其中“id”是我的存储库中文档的 ID,标签是指分配的集群。请注意,在不同的方法中,聚类的数量并不总是相同。

我准备好的另一个文档以如下形式加载到 pandas 数据框中:

GroundTruth

id    label1    label2    label3    [...]    labelM
 0         0         1         0                  1
 1         1         1         0                  0
 2         0         0         1                  0

是一种“单热编码”,注意在用户手动分配标签期间,允许多个标签(因为文档可以属于不同的主题)

现在我被比较背后的逻辑所困扰。作为第一次尝试,我这样做了:

  1. 按集群标签对集群输出中的文档进行分组
  2. 循环遍历每组中的文档
  3. 遍历 GroundTruth 数据框列并提取值 == 1(已分配标签)的行
  4. 计算 (3) 中有多少项属于 (2) 的百分比。

    for label, df_group in clusters_groups:
    docs_in_cluster = df_group['id'].values.tolist()
    # here we have a dataframe for each cluster
    for (columnName, columnData) in ground_truth.iteritems():
        overlapping = 0
        count = 0
        if columnName != 'id':
            togethers = ground_truth.loc[ground_truth[columnName] == 1, 'id']
            for doc in togethers.values.tolist():
                if int(doc) in docs_in_cluster:
                    count += 1
            overlapping = count/len(togethers.values.tolist()) * 100
    print("For label:", label, " the overlapping is: {:.2f}%".format(overlapping))
    

代码有效,但我不太相信这种方法。

有更好的方法来评估集合的重叠吗?

【问题讨论】:

    标签: python cluster-analysis


    【解决方案1】:

    您可能希望使用 groundtruth 而不是百分比重叠来计算检测到的集群标签的丰富度。

    为此,您可以使用 hnet 库,该库基于超几何测试为每个具有输入标签的 GroundTruth 计算 P 值。

    可在此处找到文档:https://erdogant.github.io/hnet。以下部分可能对您的案例感兴趣: https://erdogant.github.io/hnet/pages/html/Use%20Cases.html#cluster-enrichment

    pip install hnet
    
    # Import library
    import hnet
    
    # Run cluster enrichment using HNet
    results = hnet.enrichment(GroundTruth, label)
    
    # Examine the results
    print(results)
    

    结果是数据框的形式。第一列是 category_label,即您案例中的 GroundTruth 标签。第二列:P 代表 P-value,即 category_label 与目标变量 label 的计算显着性。带有 P 的 category_label 小于 alpha,假设 0.05 显着丰富了您的集群标签。

    【讨论】:

      猜你喜欢
      • 2020-06-26
      • 2017-02-19
      • 1970-01-01
      • 2013-05-02
      • 2017-06-08
      • 2021-01-29
      • 1970-01-01
      • 2016-03-19
      • 2012-02-24
      相关资源
      最近更新 更多