在 R 的一个城市中聚集 long/lat 个热点点的最佳方法?

Best way to cluster long/lat hotspot points in one city in R?

我是 R 和(无监督)机器学习的新手。我正在尝试为我在 R 中的数据找出最佳集群解决方案。

我的数据是关于什么的?

我有一个数据集,其中一个城市的经度/纬度 WGS84 坐标为 +/- 800。

多头在 6.90 - 6.95 范围内 纬度在 52.29 - 52.33

范围内

我想要什么?

我想根据它们的密度找到"hotspots"。例如:50 米范围内最少 5 long/lat 个点。这是一个点图示例:

我为什么要这个?

举个例子:假设每一点都是车祸。通过聚类我希望看到哪些地方需要注意。 (需要注意 x 米范围内的最小 x 点)

我发现了什么?

我的解决方案似乎可以使用以下聚类算法:

  1. DBscan (https://cran.r-project.org/web/packages/dbscan/dbscan.pdf)
  2. HDBscan(https://cran.r-project.org/web/packages/dbscan/vignettes/hdbscan.html)
  3. 光学(https://www.rdocumentation.org/packages/dbscan/versions/0.9-8/topics/optics
  4. 城市聚类算法(https://cran.r-project.org/web/packages/osc/vignettes/paper.pdf

我的问题

  1. 在 R 中适合我的案例的最佳解决方案或算法是什么?
  2. 我必须先将 long/lat 转换为距离/Haversine 矩阵是真的吗?

找到感兴趣的东西:https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

我稍微更改了此代码,使用异常值作为发生很多事情的地方

# 1. Make spatialpointsdataframe #

xy <- SpatialPointsDataFrame(
  matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
  proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

# 2. Use DISTM function to generate distance matrix.# 
mdist <- distm(xy)

# 3. Use hierarchical clustering with complete methode#
hc <- hclust(as.dist(mdist), method="complete")

# 4. Show dendogram#
plot(hc, labels = input$street, xlab="", sub="",cex=0.7)

# 5. Set distance: in my case 300 meter#
d=300

# 6. define clusters based on a tree "height" cutoff "d" and add them to the SpDataFrame
xy$clust <- cutree(hc, h=d)

# 7. Add clusters to dataset#
input$cluster <- xy@data[["clust"]]

# 8. Plot clusters #
plot(input$long, input$lat, col=input$cluster, pch=20)
text(input$long, input$lat, labels =input$cluster)

# 9. Count n in cluster#
selection2 <- input %>% count(cluster)

# 10. Make a boxplot #
boxplot(selection2$n)

#11. Get first outlier#
outlier <- boxplot.stats(selection2$n)$out
outlier <- sort(outlier)
outlier <- as.numeric(outlier[1])

#12. Filter clusters greater than outlier#
selectie3 <- as.vector(selection2 %>% filter(selection2$n >= outlier[1]) %>% select(cluster))

#13. Make a new DF with all outlier clusters#
heatclusters <- input %>% filter(cluster%in% c(selectie3$cluster))

#14. Plot outlier clusters#
plot(heatclusters$long, heatclusters$lat, col=heatclusters$cluster)

#15. Plot on density map ##
googlemap + geom_point(aes(x=long , y=lat), data=heatclusters, color="red", size=0.1, shape=".") +
  stat_density2d(data=heatclusters,
                 aes(x =long, y =lat, fill= ..level..), alpha = .2, size = 0.1,
                 bins = 10, geom = "polygon") + scale_fill_gradient(low = "green", high = "red") 

不知道这是否是一个好的解决方案。但它似乎工作。也许有人有任何其他建议?