我要找到每个星团的中心和半径。我能做什么?请帮帮我。这是我的代码它包含dbscan和meanshifts两个结果。这些点是随机的,现在我要找到每个簇的中心和半径。在
import numpy as np
import matplotlib.pyplot as plt
from sklearn import cluster
def cluster_plots(set, colours1='gray', colours2='gray',
title1='Plot 1', title2='Plot 2'):
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.set_size_inches(6, 3)
ax1.set_title(title1, fontsize=14)
ax1.set_xlim(min(set[:, 0]), max(set[:, 0]))
ax1.set_ylim(min(set[:, 1]), max(set[:, 1]))
ax1.scatter(set[:, 0], set[:, 1], s=8, lw=0, c=colours1)
ax2.set_title(title2, fontsize=14)
ax2.set_xlim(min(set[:, 0]), max(set[:, 0]))
ax2.set_ylim(min(set[:, 1]), max(set[:, 1]))
ax2.scatter(set[:, 0], set[:, 1], s=8, lw=0, c=colours2)
fig.tight_layout()
plt.show()
def data_generator():
clust1 = np.random.normal(5, 2, (1000, 2))
clust2 = np.random.normal(15, 3, (1000, 2))
clust3 = np.random.multivariate_normal([17, 3], [[1, 0], [0, 1]], 1000)
clust4 = np.random.multivariate_normal([2, 16], [[1, 0], [0, 1]], 1000)
return np.concatenate((clust1, clust2, clust3, clust4))
datapoints = data_generator()
bandwidths = [cluster.estimate_bandwidth(dataset, quantile=0.1) for dataset in [datapoints]]
meanshifts = [cluster.MeanShift(bandwidth=band, bin_seeding=True).fit(dataset) for dataset, band in zip([datapoints], bandwidths)]
dbscan = cluster.DBSCAN(eps=1, min_samples=10, metric='euclidean').fit_predict(datapoints)
cluster_plots(datapoints, dbscan,meanshifts[0].predict(datapoints),title1='DBScan', title2='Meanshifts')
我不知道该加什么才能得到我想要的。在
DBSCAN集群不使用中心或半径的概念。在
集群可以是任何形状,如果你考虑维基百科文章中的例子,如果你有这样的香蕉形状的集群,集群的“中心”可以从集群中得到回报。在
不管怎样,都没有API来获得“中心”。不管你用什么,你都得自己去找。代替算术平均值,考虑一些基于图的东西,比如图的中心性。在
相关问题 更多 >
编程相关推荐