python - Python中地理点的聚类

标签 python machine-learning cluster-analysis

我有一组 400k 个地理点(带有纬度和经度),我正在尝试将其聚类并绘制在 map 上。目前我正在使用 Folium 包的 MarkerCluster 来可视化点的聚类。但这似乎非常慢并且代码无限期地运行。

只是想知道是否有其他 Python 包可以有效地用于此目的?

当前代码:

import folium
from folium import plugins
from IPython.display import Image, clear_output, display, HTML

data = df[['StartLat','StartLong']].as_matrix()
avgLat = df['StartLat'].mean()
avgLong = df['StartLong'].mean()

mapa = folium.Map([avgLat, avgLong], zoom_start=6)
marker_cluster = folium.MarkerCluster().add_to(mapa)
latArr = np.array(df.StartLat)
lonArr = np.array(df.StartLong)

for i in range(len(latArr)):
        folium.Marker([latArr[i], lonArr[i]], icon = folium.Icon(color='green',icon='ok-sign')).add_to(marker_cluster)
mapa.save('Clustering.html')

最佳答案

让我尝试分两步回答您的问题:

  1. 你见过question here吗? ?他们也有同样的问题,即对大量地理坐标进行聚类。建议的解决方案使用 scipy.cluster

  2. 中的聚类算法
  3. 但是,对于地理纬度而言。普通的聚类分析技术可能不太适合。这主要是因为从地球表面采集的点样本往往彼此相关 ( spatial autocorrelation )。因此,这些点违反了经典统计中许多技术所固有的独立性条款。因此,如果您坚持使用 Python,我建议您查看 clusterPy 包 ( link here )。他们有几种常用于空间数据的聚类算法的实现。对空间自相关性的一些阅读也可能有助于理解某些算法通常需要作为参数的考虑因素(例如距离带)。

关于python - Python中地理点的聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40745437/

相关文章:

python - 在编码 Visual Studio + PTVS 时是否可以使用基于远程 vagrant 的 python 解释器

r - 使用神经网络包进行多项分类

python - Scikit 多类分类指标,分类报告

python - 如何在 python 中执行具有权重/密度的集群?有权重的 kmeans 之类的东西?

Python Pandas - 合并列表中每个项目的数据帧

"default"条件语句的 Pythonic 方式?

machine-learning - 如何在两个不同的 keras 层之间创建自定义(卷积)连接

r - 短语的无监督语义聚类

python - BIC 使用 scikit-learn 中的 GaussianMixture 过度拟合图像分割模型中的组件数量

python - MySQL 选择具有几乎相同值的多行