在R的一个城市聚集长/纬度热点点的最佳方法?
我不熟悉R和(无监督的)机器学习。我正试图为我在R中的数据找到最好的群集解决方案 我的数据是关于什么的? 我在一个城市有一个+/-800长/纬度WGS84坐标的数据集 Long在6.90到6.95之间 lat在52.29-52.33之间 我想要什么? 我想根据它们的密度找到“热点”。例如:50米范围内至少5个长/横向点。这是一个点图示例: 我为什么要这个? 例如:让我们假设每个点都是车祸。我希望通过对这些要点进行聚类,看看哪些领域需要关注。(需要注意x米范围内的最小x点) 我找到了什么? 以下群集算法似乎适用于我的解决方案:在R的一个城市聚集长/纬度热点点的最佳方法?,r,algorithm,cluster-analysis,hierarchical-clustering,unsupervised-learning,R,Algorithm,Cluster Analysis,Hierarchical Clustering,Unsupervised Learning,我不熟悉R和(无监督的)机器学习。我正试图为我在R中的数据找到最好的群集解决方案 我的数据是关于什么的? 我在一个城市有一个+/-800长/纬度WGS84坐标的数据集 Long在6.90到6.95之间 lat在52.29-52.33之间 我想要什么? 我想根据它们的密度找到“热点”。例如:50米范围内至少5个长/横向点。这是一个点图示例: 我为什么要这个? 例如:让我们假设每个点都是车祸。我希望通过对这些要点进行聚类,看看哪些领域需要关注。(需要注意x米范围内的最小x点) 我找到了什么? 以下
查找对以下内容感兴趣的内容: 我稍微修改了这段代码,使用异常值作为发生大量事件的地方
# 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)
不知道这是否是一个好的解决方案。但它似乎奏效了。可能有人有其他建议吗?查找感兴趣的内容: 我稍微修改了这段代码,使用异常值作为发生大量事件的地方
# 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)
不知道这是否是一个好的解决方案。但它似乎奏效了。也许有人有其他建议
#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")