HDBSCAN Python 选择簇数
HDBSCAN Python choose number of clusters
是否可以selectpython中HDBSCAN算法的簇数?或者唯一的方法是玩弄输入参数,例如 alpha,min_cluster_size?
谢谢
更新:
这是使用 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')
如果您明确需要获得固定数量的集群,那么最接近管理的方法是使用集群层次结构,并在为您提供所需数量的集群的级别上对层次结构进行平面切割。这确实涉及处理 HDBSCAN 公开的树对象之一并让您的手有点脏,但这是可以做到的。
值得庆幸的是,2020 年 6 月,GitHub (Module for flat clustering) 的一位贡献者提供了一个向 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 您应该能够使用 approximate_predict_flat 选择测试点的簇数。
另外,还写了一个jupyter notebook,说明使用方法,Here。
是否可以selectpython中HDBSCAN算法的簇数?或者唯一的方法是玩弄输入参数,例如 alpha,min_cluster_size?
谢谢
更新: 这是使用 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')
如果您明确需要获得固定数量的集群,那么最接近管理的方法是使用集群层次结构,并在为您提供所需数量的集群的级别上对层次结构进行平面切割。这确实涉及处理 HDBSCAN 公开的树对象之一并让您的手有点脏,但这是可以做到的。
值得庆幸的是,2020 年 6 月,GitHub (Module for flat clustering) 的一位贡献者提供了一个向 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 您应该能够使用 approximate_predict_flat 选择测试点的簇数。
另外,还写了一个jupyter notebook,说明使用方法,Here。