我使用dbscan算法对地理空间数据进行了聚类。您可以在这里更详细地看到项目和代码:https://notebook.community/gboeing/urban-data-science/15-Spatial-Cluster-Analysis/cluster-analysis
我想在一个dataframe中计算以下内容:
目前,我已经在原始数据集中添加了一个列,其中包含坐标所属的集群。
for n in range(num_clusters):
df['cluster'] = pd.Series(cluster_labels, index=df.index)有什么简单的代码可以让我这么做吗?
发布于 2022-11-14 09:14:53
一个简单的解决方案是将Voronoi图应用于DB扫描集群:
您可以获得多边形坐标并计算多边形面积,如下所示:
import numpy as np
x = np.arange(0,1,0.001)
y = np.sqrt(1-x**2)
def PolyArea(x,y):
return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1)))资料来源:
https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Voronoi.html
https://datascience.stackexchange.com/questions/116133
复制相似问题