用于映射的聚类算法

时间:2016-07-07 07:43:17

标签: r google-maps gis cluster-analysis k-means

我在地图上有很多点(长/纬),我想将它们聚类到群组, 就像k-means一样。

有什么方法可以插入点(长/纬)和组数,并获得每个点所属的组?

2 个答案:

答案 0 :(得分:0)

library(ggplot2)

# Construct Data
set.seed(23)
lat <- c(seq(from = 16.3478, to = 14.1329876, length.out = 500),
seq(from = 18.5478, to = 19.567, length.out = 500))
lat <- sample(x = lat, size = 100)

lon <- seq(from = 45.987, to = 46.98237, length.out = 1000)
lon <- sample(x = lon, size = 100)

# Place inside data.frame
df_latlon <- data.frame(lat, lon)

cluster_latlon <- kmeans(x = df_latlon, centers = 2, nstart = 20)
df_latlon <- cbind(df_latlon, cluster_latlon$cluster)

# Output ggplot with colored values
ggplot(df_latlon) + 
geom_point(aes(lat, lon, color = as.factor(cluster_latlon$cluster))) 

cluster_latlon$centers
cluster_latlon$cluster

答案 1 :(得分:0)

你的问题基本上是&#34;我如何进行聚类&#34;。

无法简明扼要地回答,但您应该阅读有关群集的教科书。

k-means不适用于纬度和经度,因为它是最小二乘法,但1度纬度不等于1度经度(通常)。使用PAM,分层聚类,DBSCAN等