我有使用 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 个集群,每个文档在不同的集群中。我尝试更改不同的参数。但聚类结果没有变化。
非常感谢任何建议或参考。