是否可以在Python中的HDBSCAN算法中选择簇的数量?或者唯一的方法是使用输入参数,例如 alpha、min_cluster_size?
Thanks
UPDATE:这是使用 fcluster 和 hdbscan 的代码
import hdbscan
from scipy.cluster.hierarchy import fcluster
clusterer = hdbscan.HDBSCAN()
clusterer.fit(X)
Z = clusterer.single_linkage_tree_.to_numpy()
labels = fcluster(Z, 2, criterion='maxclust')
值得庆幸的是,2020 年 6 月,GitHub 上的一位贡献者 (平面聚类模块 https://github.com/scikit-learn-contrib/hdbscan/pull/398)提供了一个提交,将代码添加到 hdbscan 中,使我们能够选择生成的集群的数量。
为此:
from hdbscan import flat
clusterer = flat.HDBSCAN_flat(train_df, n_clusters, prediction_data=True)
flat.approximate_predict_flat(clusterer, points_to_predict, n_clusters)
您可以在这里找到代码flat.py https://github.com/scikit-learn-contrib/hdbscan/blob/master/hdbscan/flat.py您应该能够使用 approximation_predict_flat 选择测试点的簇数。
另外,还写了一个jupyter笔记本解释如何使用,Here https://github.com/scikit-learn-contrib/hdbscan/blob/master/notebooks/Flat%20clustering.ipynb.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)