Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获得每个已识别集群的数据点计数?_Python_Python 3.x - Fatal编程技术网

Python 如何获得每个已识别集群的数据点计数?

Python 如何获得每个已识别集群的数据点计数?,python,python-3.x,Python,Python 3.x,我做了聚类,得到了3个聚类。现在,我想得到一个数据帧,它返回每个集群的数据点数。例如: [Cluster, count] [0,50] [1,30] [2,10] 这就是我取得的成绩: X=array([[5.71585827e+00, 3.32320000e+04], [0.00000000e+00, 0.00000000e+00], [0.00000000e+00, 0.00000000e+00], ..., [9.57746479e

我做了聚类,得到了3个聚类。现在,我想得到一个数据帧,它返回每个集群的数据点数。例如:

[Cluster, count]
[0,50]
[1,30]
[2,10]
这就是我取得的成绩:

X=array([[5.71585827e+00, 3.32320000e+04],
       [0.00000000e+00, 0.00000000e+00],
       [0.00000000e+00, 0.00000000e+00],
       ...,
       [9.57746479e-02, 3.40000000e+01],
       [7.01388889e-01, 1.01000000e+02],
       [9.70350404e-02, 3.60000000e+01]])

#Scale
X = StandardScaler().fit_transform(X)

# Compute DBSCAN
db = DBSCAN(eps=0.25, min_samples=10).fit(X)
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_

# Number of clusters in labels, ignoring noise if present.
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
n_noise_ = list(labels).count(-1)



df = pd.DataFrame({'cluster':list(set(labels)),'customers':len(X) })
df.head()

cluster customers
0       90
1       90
2       90

当然,“客户”一栏是完全错误的!如何获得每个集群类的正确计数?

为什么不计算每个标签出现的次数?差不多

pd.Series(labels).value\u counts()


如果你正在使用熊猫

有人能帮忙吗?太好了!对不起,这件事太琐碎了。