Python 3.x 使用HDBSCAN群集时获取群集中心
对集群和尝试HDBSCAN集群非常陌生,但我很难弄清楚如何获得集群中心。使用KMeans时,它与集群一起设置 如何获得群集中心 这是我的密码:Python 3.x 使用HDBSCAN群集时获取群集中心,python-3.x,cluster-analysis,Python 3.x,Cluster Analysis,对集群和尝试HDBSCAN集群非常陌生,但我很难弄清楚如何获得集群中心。使用KMeans时,它与集群一起设置 如何获得群集中心 这是我的密码: #!/usr/bin/env python3 from sklearn.cluster import KMeans from sklearn import metrics import cv2 import numpy as np import hdbscan from pprint import pprint # Read image into
#!/usr/bin/env python3
from sklearn.cluster import KMeans
from sklearn import metrics
import cv2
import numpy as np
import hdbscan
from pprint import pprint
# Read image into opencv
image = cv2.imread('4.jpg')
# Set color space
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# reshape the image to be a list of pixels
pixels = image.reshape((image.shape[0] * image.shape[1], 3))
# Build the clusterer
cluster = hdbscan.RobustSingleLinkage(cut=0.125, k=7)
cluster.fit(pixels)
>>> pprint(vars(cluster))
{'_cluster_hierarchy_': <hdbscan.plots.SingleLinkageTree object at 0x110deda58>,
'_metric_kwargs': {},
'algorithm': 'best',
'alpha': 1.4142135623730951,
'core_dist_n_jobs': 4,
'cut': 0.125,
'gamma': 5,
'k': 7,
'labels_': array([ 0, 0, 0, ..., 360, 220, 172]),
'metric': 'euclidean'}
(H)dbs中的簇可以没有中心
这些簇可能是非凸的,如果你计算所有点的平均值(你的数据是点——它们不需要是),那么它可能就在簇之外
另外请注意,DBSCAN还提供了噪声点,这些噪声点根本没有中心。感谢您的回答并将其标记为重复。另一个问题的措辞不同,所以在我的搜索中没有出现。我需要重新表述我的问题和代码,以缩小问题+原始问题的范围。
{'cluster_centers': (array([ 64.93473757, 65.65262431, 72.00103591]),
array([ 77.55381605, 85.80626223, 102.29549902]),
array([ 105.66884532, 115.81917211, 131.55555556]),
array([ 189.20149254, 197.00497512, 205.43034826]),
array([ 148.0922619 , 156.5 , 168.33333333])),
'cluster_centers_': array([[ 105.66884532, 115.81917211, 131.55555556],
[ 64.93473757, 65.65262431, 72.00103591],
[ 148.0922619 , 156.5 , 168.33333333],
[ 189.20149254, 197.00497512, 205.43034826],
[ 77.55381605, 85.80626223, 102.29549902]]),
'copy_x': True,
'inertia_': 1023155.888923295,
'init': 'k-means++',
'labels_': array([1, 1, 1, ..., 1, 1, 1], dtype=int32),
'max_iter': 300,
'n_clusters': 5,
'n_init': 10,
'n_iter_': 8,
'n_jobs': 1,
'precompute_distances': 'auto',
'random_state': None,
'tol': 0.0001,
'verbose': 0}