首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在dbscan聚类后执行一些计算

如何在dbscan聚类后执行一些计算
EN

Data Science用户
提问于 2022-11-13 10:58:43
回答 1查看 27关注 0票数 0

我使用dbscan算法对地理空间数据进行了聚类。您可以在这里更详细地看到项目和代码:https://notebook.community/gboeing/urban-data-science/15-Spatial-Cluster-Analysis/cluster-analysis

我想在一个dataframe中计算以下内容:

  • 每组的面积。它可以计算为:(lat_max - lat_min) * (lon_max - lon_min)
  • 属于每一组的点数

目前,我已经在原始数据集中添加了一个列,其中包含坐标所属的集群。

代码语言:javascript
复制
for n in range(num_clusters):
    df['cluster'] = pd.Series(cluster_labels, index=df.index)

有什么简单的代码可以让我这么做吗?

EN

回答 1

Data Science用户

回答已采纳

发布于 2022-11-14 09:14:53

一个简单的解决方案是将Voronoi图应用于DB扫描集群:

https://www.arianarab.com/post/unsupervised-point-pattern-clustering-using-voronoi-tessellation-and-density-based-scan-algorithms

您可以获得多边形坐标并计算多边形面积,如下所示:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/116133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档