从 NbClust 中检索最佳数量的簇
Retrieve best number of clusters from NbClust
R 中的许多函数都提供某种控制台输出(例如 NbClust() 等)。有没有什么方法可以在不查看输出的情况下检索某些输出(例如某个整数值)?从控制台读取的任何方式?
假设输出类似于 package manual 中提供的示例代码的以下输出:
[1] "Frey index : No clustering structure in this data set"
*** : The Hubert index is a graphical method of determining the number of clusters.
In the plot of Hubert index, we seek a significant knee that corresponds to a
significant increase of the value of the measure i.e the significant peak in Hubert
index second differences plot.
*** : The D index is a graphical method of determining the number of clusters.
In the plot of D index, we seek a significant knee (the significant peak in Dindex
second differences plot) that corresponds to a significant increase of the value of
the measure.
*******************************************************************
* Among all indices:
* 1 proposed 2 as the best number of clusters
* 2 proposed 4 as the best number of clusters
* 2 proposed 6 as the best number of clusters
* 1 proposed 7 as the best number of clusters
***** Conclusion *****
* According to the majority rule, the best number of clusters is 4
*******************************************************************
如何从上述输出的最后一行检索值 4?
最好使用对象而不是在控制台中输出。任何 "good" 函数都会 return 希望结构化输出可以使用 $
或 @
符号访问,使用 str()
查看对象的结构。
对于你的情况,我认为这应该可行:
length(unique(res$Best.partition))
另一种选择是:
max(unlist(res[4]))
R 中的许多函数都提供某种控制台输出(例如 NbClust() 等)。有没有什么方法可以在不查看输出的情况下检索某些输出(例如某个整数值)?从控制台读取的任何方式?
假设输出类似于 package manual 中提供的示例代码的以下输出:
[1] "Frey index : No clustering structure in this data set"
*** : The Hubert index is a graphical method of determining the number of clusters.
In the plot of Hubert index, we seek a significant knee that corresponds to a
significant increase of the value of the measure i.e the significant peak in Hubert
index second differences plot.
*** : The D index is a graphical method of determining the number of clusters.
In the plot of D index, we seek a significant knee (the significant peak in Dindex
second differences plot) that corresponds to a significant increase of the value of
the measure.
*******************************************************************
* Among all indices:
* 1 proposed 2 as the best number of clusters
* 2 proposed 4 as the best number of clusters
* 2 proposed 6 as the best number of clusters
* 1 proposed 7 as the best number of clusters
***** Conclusion *****
* According to the majority rule, the best number of clusters is 4
*******************************************************************
如何从上述输出的最后一行检索值 4?
最好使用对象而不是在控制台中输出。任何 "good" 函数都会 return 希望结构化输出可以使用 $
或 @
符号访问,使用 str()
查看对象的结构。
对于你的情况,我认为这应该可行:
length(unique(res$Best.partition))
另一种选择是:
max(unlist(res[4]))