按照 Scikit Learning的 DBSCAN 聚类算法的示例演示,我试图将每个聚类类的 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 存储在一个数组中