微调hdbscan参数以将文本文档聚类

时间:2018-10-01 12:28:03

标签: python scikit-learn cluster-analysis hdbscan

我有一些文本文档正在使用hdbsca进行聚类。当我拥有约35个文档的激光量数据并校正了约14个簇的值时,使用以下参数,我将得到正确的结果。

def cluster_texts(textdict, eps=0.40,min_samples = 1):
    """
    cluster the given texts
    Input:
        textdict: dictionary with {docid: text}
    Returns:
        doccats: dictionary with {docid: cluster_id}
    """
    doc_ids = list(textdict.keys())
    # transform texts into length normalized kpca features
    ft = FeatureTransform(norm='max', weight=True, renorm='length', norm_num=False)
    docfeats = ft.texts2features(textdict)
    X, featurenames = features2mat(docfeats, doc_ids)
    e_lkpca = KernelPCA(n_components=12, kernel='linear')
    X = e_lkpca.fit_transform(X)
    xnorm = np.linalg.norm(X, axis=1)
    X = X/xnorm.reshape(X.shape[0], 1)
    # compute cosine similarity
    D = 1 - linear_kernel(X)
    # and cluster with dbscan
    clst = hdbscan.HDBSCAN(eps=eps, metric='precomputed', min_samples=min_samples,gen_min_span_tree=True,min_cluster_size=2)
    y_pred = clst.fit_predict(D)

    return {did: y_pred[i] for i, did in enumerate(doc_ids)}

现在我只复制了数据,每个文档100次。并尝试微调集群,但是现在我得到了36个集群,每个文档都位于不同的集群中。我尝试更改其他参数。但聚类结果没有变化。

任何建议或参考均不胜感激。

1 个答案:

答案 0 :(得分:1)

很明显,如果将每个点复制100次,则还需要将minPts参数增加100x并最小化群集大小。

但是您的主要问题可能是KernelPCA,它对您拥有的样本数量敏感,而不是HDBSCAN。

相关问题