2016-07-07 2 views
-2

지도 (long/Lat)에 많은 점이 있으며 그룹에 그룹화하려는 경우 k- 수단과 비슷합니다.지도 작성을위한 클러스터링 알고리즘

포인트 (긴/위도) 및 그룹 수를 삽입하고 그녀가 속한 그룹의 각 포인트를 얻는 방법은 무엇입니까?

+0

[좋은 질문을하는 방법] (http://stackoverflow.com/help/how-to-ask) 및 [재현 가능 예] (http://stackoverflow.com/questions/5963269). 이렇게하면 다른 사람들이 당신을 도울 수있게됩니다. – zx8754

+0

도움이 될 것입니다. http://stackoverflow.com/questions/28672399/spatial-clustering-in-r-simple-example –

답변

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 
0

귀하의 질문은 본질적으로 "클러스터링을 어떻게 수행합니까?"입니다.

간결하게 대답 할 수는 없지만 클러스터링에 대한 교과서를 읽어야합니다.

k-means는 최소 제곱 접근이기 때문에 위도와 경도에 적합하지 않지만 1도 위도는 경도 1도 (일반적으로)와 같지 않으므로 k- 수단은 적합하지 않습니다. PAM, 계층 적 클러스터링, DBSCAN 등을 사용하십시오.

관련 문제