Caret包findCorrelation()函数

时间:2016-01-29 23:00:28

标签: r correlation r-caret

您好我的 findCorrelation()功能有问题,这是我的输入和输出:

findCorrelation(train, cutoff = .50, verbose = FALSE)
  

findCorrelation_exact出错(x = x,cutoff = cutoff,verbose =   详细):相关矩阵不对称

有谁知道为什么会这样?

3 个答案:

答案 0 :(得分:11)

findCorrelation函数需要将相关矩阵作为x值,因此请尝试以下方法:

findCorrelation(cor(train), cutoff = .50, verbose = FALSE)

参考:Caret pre-processing

答案 1 :(得分:2)

嗯,这是因为矩阵可能没有列数(或反之亦然)。例如。

library(caret)
train <- cor(mtcars)
findCorrelation(train, cutoff = .50, verbose = FALSE)
# works
findCorrelation(train[, -1], cutoff = .50, verbose = FALSE)
# Error in findCorrelation_exact(x = x, cutoff = cutoff, verbose = verbose) : 
#   correlation matrix is not symmetric
dim(train[, -1])
# [1] 11 10

(根据错误信息,至少这是我的猜测。)

答案 2 :(得分:1)

如果使用的是数据框,则可能必须先将其制成矩阵。

--with-python=3