使用以下代码:http ://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering
以下是如何生成树状图:
# import data
x <- read.table("data.txt")
# run AGNES
ag <- agnes (x, false, metric="euclidean", false, method ="single")
# print components of ag
print(ag)
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)
我收到一个错误
ag <- agnes (x, false, metric="euclidean", false, method ="single")
错误是:
Error in agnes(x, false, metric = "euclidean", false, method = "single") :
object 'false' not found
agnes 的这种实现有效,但它为树状图生成编号标签:
ag <- agnes (data, metric="euclidean")
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)
树状图:
生成的树状图http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering
包括标签:
这是数据文件:
,ba,fi,mi,vo,rm,to
ba,0,662,877,255,412,996
fi,662,0,295,468,268,400
mi,877,295,0,754,564,138
vo,255,468,754,0,219,869
rm,412,268,564,219,0,669
to,996,400,138,869,669,0
如何根据上述数据生成与上面标记的树状图相同的标记层次聚类?
更新 :
在遵循@sgibb 的建议后,我使用了这个:
ag <- agnes(data, FALSE, metric="euclidean", FALSE, method ="single")
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)
正在生成的树状图现在是:
这是一个不正确的结构。也许是因为我的数据集的列名显示为 1,2,3,4,5,6 并且没有标记,如果是这样,我该如何修改导入语句?
导入的数据集: