【问题标题】:DBSCAN in scikit-learn of Python: save the cluster points in an arrayPython scikit-learn 中的 DBSCAN:将聚类点保存在数组中
【发布时间】:2013-08-16 17:52:31
【问题描述】:

按照 Scikit Learning 的示例Demo of DBSCAN clustering algorithm,我试图将每个聚类类的 x、y 存储在一个数组中

import numpy as np
from sklearn.cluster import DBSCAN
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import StandardScaler
from pylab import *

# Generate sample data
centers = [[1, 1], [-1, -1], [1, -1]]
X, labels_true = make_blobs(n_samples=750, centers=centers, cluster_std=0.4, random_state=0)
X = StandardScaler().fit_transform(X) 

xx, yy = zip(*X)
scatter(xx,yy)
show()

db = DBSCAN(eps=0.3, min_samples=10).fit(X)
core_samples = db.core_sample_indices_
labels = db.labels_
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
print n_clusters_
3

我正在尝试通过 scikit-learn 了解 DBSCAN 实现,但从这一点开始我遇到了麻烦。簇数为 3(n_clusters_),我希望将每个簇的 x、y 存储在一个数组中

【问题讨论】:

    标签: python cluster-analysis scikit-learn dbscan


    【解决方案1】:

    第一个集群是X[labels == 0]等:

    clusters = [X[labels == i] for i in xrange(n_clusters_)]
    

    异常值是

    outliers = X[labels == -1]
    

    【讨论】:

      【解决方案2】:

      “每个集群”是什么意思?

      在 DBSCAN 中,集群不像 k-means 中那样表示为质心,因此除了其成员之外,没有明显的集群表示。您已经有了集群成员的 x 和 y 位置,因为它们是输入数据。

      所以我不确定问题是什么。

      【讨论】:

      • 嘿安德烈亚斯,对不起,如果我不清楚。如果您在图 2 中看到,每个点 (x, y) 由于集群而具有不同的颜色(例如,示例中的 3 个集群和后面的点是噪声)。我希望有一个包含 3 个块的数组。每个块存储该集群的 x、y 点值。
      • 你有集群成员的 x 和 y 位置,但是你怎么知道这些点在哪个集群中?
      • @user3378649,有对应其集群的标签。 dbscan.labels_
      猜你喜欢
      • 2019-04-15
      • 2016-06-25
      • 2015-11-20
      • 2014-10-02
      • 2016-06-07
      • 2015-03-05
      • 2013-04-29
      • 2018-09-17
      • 2014-09-11
      相关资源
      最近更新 更多