【发布时间】:2021-02-15 14:12:11
【问题描述】:
因此,我和其他一些同事开发了一种层次聚类算法,基本上可以根据特定城市(例如伦敦市)找到涉及农业产业的主要聚类。我们在 R 中构建了这个算法。它运行良好。因此,根据我们在算法中插入的过滤器,我们能够为伦敦市生成 6 个聚类场景。例如,第一个场景生成 2 个集群,第二个场景生成 5 个集群,以此类推。因此,我想就如何选择最合适的人提供一些帮助。我看到有一些包在这个过程中有所帮助,比如pvclust,但我不能将它用于我的案例。我在下面插入一个简短的可执行代码来展示我想要的本质。
欢迎任何帮助!如果您知道如何使用其他包,请随时描述。
最好的问候。
library(rdist)
library(geosphere)
library(fpc)
df<-structure(list(Industries = c(1,2,3,4,5,6),
+ Latitude = c(-23.8, -23.8, -23.9, -23.7, -23.7,-23.7),
+ Longitude = c(-49.5, -49.6, -49.7, -49.8, -49.6,-49.9),
+ Waste = c(526, 350, 526, 469, 534, 346)), class = "data.frame", row.names = c(NA, -6L))
df1<-df
#clusters
coordinates<-df[c("Latitude","Longitude")]
d<-as.dist(distm(coordinates[,2:1]))
fit.average<-hclust(d,method="average")
clusters<-cutree(fit.average, k=2)
df$cluster <- clusters
> df
Industries Latitude Longitude Waste cluster
1 1 -23.8 -49.5 526 1
2 2 -23.8 -49.6 350 1
3 3 -23.9 -49.7 526 1
4 4 -23.7 -49.8 469 2
5 5 -23.7 -49.6 534 1
6 6 -23.7 -49.9 346 2
>
clusters1<-cutree(fit.average, k=5)
df1$cluster <- clusters1
> df1
Industries Latitude Longitude Waste cluster
1 1 -23.8 -49.5 526 1
2 2 -23.8 -49.6 350 1
3 3 -23.9 -49.7 526 2
4 4 -23.7 -49.8 469 3
5 5 -23.7 -49.6 534 4
6 6 -23.7 -49.9 346 5
>
【问题讨论】:
-
查看Cluster Analysis Task View,特别是附加功能部分。包
clValid可能有你想要的。
标签: r cluster-analysis hierarchical-clustering