【问题标题】:How to generate a labelled dendogram using agnes?如何使用 agnes 生成标记的树状图?
【发布时间】:2013-09-15 21:03:11
【问题描述】:

使用来自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 并且没有标记,如果是这样我该如何修改导入语句?

导入的数据集:

【问题讨论】:

  • 在R中你必须使用FALSE而不是false!我不知道agnes,但试试agnes(x, FALSE, metric="euclidean", FALSE, method ="single")
  • @sgibb 谢谢,FALSE 确实导致它不会引发错误,但标签仍然无法正常工作。并且树状图看起来不正确。请查看问题更新
  • 这似乎不是关于创建树状图的问题,而是关于如何正确导入数据的问题。

标签: r hierarchical-clustering dendrogram


【解决方案1】:

我的问题是数据集中多了一个逗号。

running help(read.table) 并记下本节帮助我解决了问题:

If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered.

这行得通:

  1. 通过 r gui 导入数据 要导入的数据:

    ba,fi,mi,vo,rm,to 巴,0,662,877,255,412,996 fi,662,0,295,468,268,400 英里,877,295,0,754,564,138 VO,255,468,754,0,219,869 rm,412,268,564,219,0,669 至,996,400,138,869,669,0

  2. 运行命令:

ag

plot(ag, ask = FALSE, which.plots = NULL)

这会生成这个看起来正确的树状图:

【讨论】:

  • 我对 Q 和 A 投了赞成票,因为链接到 wikibooks 示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-15
  • 2011-02-27
相关资源
最近更新 更多