Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R将集群摘要对象转换为数据帧_R_Validation_Cluster Analysis - Fatal编程技术网

R将集群摘要对象转换为数据帧

R将集群摘要对象转换为数据帧,r,validation,cluster-analysis,R,Validation,Cluster Analysis,我试图从使用创建的R集群验证对象中提取验证度量 当我创建对象并打印完整摘要时,我使用以下命令 library(clValid) x <- clValid(iris[, -5], nClust=2:10, clMethods=c('hierarchical'), validation='internal') summary(x) 所需输出 我试图将验证度量值作为如下数据帧: 2 3 4

我试图从使用创建的R集群验证对象中提取验证度量

当我创建对象并打印完整摘要时,我使用以下命令

library(clValid)

x <- clValid(iris[, -5], nClust=2:10,
        clMethods=c('hierarchical'), validation='internal')
summary(x)
所需输出

我试图将
验证度量值
作为如下数据帧:

                                2       3       4       5       6       7       8       9      10

hierarchical Connectivity   0.0000  4.4770  8.9929 15.4893 18.4183 24.8464 29.8425 36.8567 39.5607
             Dunn           0.3389  0.1378  0.1540  0.1540  0.1668  0.1624  0.1624  0.1915  0.1915
             Silhouette     0.6867  0.5542  0.4720  0.4307  0.3420  0.3707  0.3659  0.3167  0.3083
尝试

当我使用:

names(summary(x))
attributes(summary(x))
这两个都给

NULL
我可以使用
optimalScores(x)
获得最佳分数,但是,这不适用于
validationMeasures(x)

问题


是否有方法将
验证度量值
提取为此摘要对象的
数据框

str(x)
Formal class 'clValid' [package "clValid"] with 14 slots
  ..@ clusterObjs:List of 1
  .. ..$ hierarchical:List of 7
  .. .. ..$ merge      : int [1:149, 1:2] -102 -8 -1 -10 -129 -11 -5 -20 -30 -58 ...
  .. .. ..$ height     : num [1:149] 0 0.1 0.1 0.1 0.1 ...
  .. .. ..$ order      : int [1:150] 42 15 16 33 34 37 21 32 44 24 ...
  .. .. ..$ labels     : NULL
  .. .. ..$ method     : chr "average"
  .. .. ..$ call       : language hclust(d = Dist, method = method)
  .. .. ..$ dist.method: chr "euclidean"
  .. .. ..- attr(*, "class")= chr "hclust"
  ..@ measures   : num [1:3, 1:9, 1] 0 0.339 0.687 4.477 0.138 ...
  .. ..- attr(*, "dimnames")=List of 3
  .. .. ..$ : chr [1:3] "Connectivity" "Dunn" "Silhouette"
  .. .. ..$ : chr [1:9] "2" "3" "4" "5" ...
  .. .. ..$ : chr "hierarchical"
  ..@ measNames  : chr [1:3] "Connectivity" "Dunn" "Silhouette"
  ..@ clMethods  : chr "hierarchical"
  ..@ labels     : chr [1:150] "1" "2" "3" "4" ...
  ..@ nClust     : num [1:9] 2 3 4 5 6 7 8 9 10
  ..@ validation : chr "internal"
  ..@ metric     : chr "euclidean"
  ..@ method     : chr "average"
  ..@ neighbSize : num 10
  ..@ annotation : NULL
  ..@ GOcategory : chr "all"
  ..@ goTermFreq : num 0.05
  ..@ call       : language clValid(obj = iris[, -5], nClust = 2:10, clMethods = c("hierarchical"),      validation = "internal")
因此,我们可以看到这个包使用并返回
S4
对象,其中一个插槽
度量值似乎就是您想要的

x@measures[,,"hierarchical"]
                     2         3         4          5          6          7
Connectivity 0.0000000 4.4769841 8.9928571 15.4892857 18.4182540 24.8464286
Dunn         0.3389087 0.1378257 0.1540416  0.1540416  0.1668323  0.1624158
Silhouette   0.6867351 0.5541609 0.4719936  0.4306700  0.3419904  0.3707424
                      8          9         10
Connectivity 29.8424603 36.8567460 39.5607143
Dunn          0.1624158  0.1914854  0.1914854
Silhouette    0.3658753  0.3166807  0.3082851

首先,你应该一直尝试

str(x)
Formal class 'clValid' [package "clValid"] with 14 slots
  ..@ clusterObjs:List of 1
  .. ..$ hierarchical:List of 7
  .. .. ..$ merge      : int [1:149, 1:2] -102 -8 -1 -10 -129 -11 -5 -20 -30 -58 ...
  .. .. ..$ height     : num [1:149] 0 0.1 0.1 0.1 0.1 ...
  .. .. ..$ order      : int [1:150] 42 15 16 33 34 37 21 32 44 24 ...
  .. .. ..$ labels     : NULL
  .. .. ..$ method     : chr "average"
  .. .. ..$ call       : language hclust(d = Dist, method = method)
  .. .. ..$ dist.method: chr "euclidean"
  .. .. ..- attr(*, "class")= chr "hclust"
  ..@ measures   : num [1:3, 1:9, 1] 0 0.339 0.687 4.477 0.138 ...
  .. ..- attr(*, "dimnames")=List of 3
  .. .. ..$ : chr [1:3] "Connectivity" "Dunn" "Silhouette"
  .. .. ..$ : chr [1:9] "2" "3" "4" "5" ...
  .. .. ..$ : chr "hierarchical"
  ..@ measNames  : chr [1:3] "Connectivity" "Dunn" "Silhouette"
  ..@ clMethods  : chr "hierarchical"
  ..@ labels     : chr [1:150] "1" "2" "3" "4" ...
  ..@ nClust     : num [1:9] 2 3 4 5 6 7 8 9 10
  ..@ validation : chr "internal"
  ..@ metric     : chr "euclidean"
  ..@ method     : chr "average"
  ..@ neighbSize : num 10
  ..@ annotation : NULL
  ..@ GOcategory : chr "all"
  ..@ goTermFreq : num 0.05
  ..@ call       : language clValid(obj = iris[, -5], nClust = 2:10, clMethods = c("hierarchical"),      validation = "internal")
因此,我们可以看到这个包使用并返回
S4
对象,其中一个插槽
度量值似乎就是您想要的

x@measures[,,"hierarchical"]
                     2         3         4          5          6          7
Connectivity 0.0000000 4.4769841 8.9928571 15.4892857 18.4182540 24.8464286
Dunn         0.3389087 0.1378257 0.1540416  0.1540416  0.1668323  0.1624158
Silhouette   0.6867351 0.5541609 0.4719936  0.4306700  0.3419904  0.3707424
                      8          9         10
Connectivity 29.8424603 36.8567460 39.5607143
Dunn          0.1624158  0.1914854  0.1914854
Silhouette    0.3658753  0.3166807  0.3082851

谢谢我根本不知道
str()
。这似乎很有用。我真的很挣扎。再次感谢,谢谢。我根本不知道
str()
。这似乎很有用。我真的很挣扎。再次感谢。