我有一个坐标数据数组(在Web Mercator Eastings和Northings中,因此以米为单位),如下所示:
array([[ -232372.201264, 6785082.61011 ],
[ -233396.451899, 6784865.49884 ],
[ -234045.110572, 6784642.2575 ],
...,
[ -234473.356653, 6778646.81953 ],
[ -234918.300657, 6778772.69366 ],
[ -230900.668915, 6778369.2902 ]])
此数组存储为变量'coords'。
我正在尝试使用Scikit Learn和DBSCAN计算 - 然后绘制 - 此数据集中的聚类(感谢this帖子让我这么做。)
我使用的代码来自this教程,但是我收到属性错误。代码和错误如下所示:
db = DBSCAN(eps=0.2, min_samples=1, metric="precomputed")
cluster_labels = db.labels_
num_clusters = len(set(cluster_labels))
clusters = pd.Series([coords[cluster_labels == n] for n in range(num_clusters)])
print('Number of clusters: {}'.format(num_clusters))
...
AttributeError: 'DBSCAN' object has no attribute 'labels_'
有谁可以解释我哪里出错?
答案 0 :(得分:4)
您遗失fit
:
db = DBSCAN(eps=0.2, min_samples=1, metric="precomputed")
db.fit(data)
cluster_labels = db.labels_
num_clusters = len(set(cluster_labels))
clusters = pd.Series([coords[cluster_labels == n] for n in range(num_clusters)])
print('Number of clusters: {}'.format(num_clusters))
答案 1 :(得分:2)
您必须将其称为
db=DBSCAN(eps=0.2, min_samples=1, metric="precomputed").fit(mymatrix)
(请注意fit()
功能)