你好,我在使用findCorrelation()函数时遇到了困难。这是我的输入和输出:
findCorrelation(train, cutoff = .50, verbose = FALSE)
在查找相关性时出现错误,具体为:x = x,截断值为cutoff,是否详细显示为verbose。错误原因是:相关矩阵不对称。
有没有人知道这是为什么?
你好,我在使用findCorrelation()函数时遇到了困难。这是我的输入和输出:
findCorrelation(train, cutoff = .50, verbose = FALSE)
在查找相关性时出现错误,具体为:x = x,截断值为cutoff,是否详细显示为verbose。错误原因是:相关矩阵不对称。
有没有人知道这是为什么?
findCorrelation函数希望x值是相关矩阵,所以请尝试使用以下方法:
findCorrelation(cor(train), cutoff = .50, verbose = FALSE)
参考资料: Caret预处理
这通常发生在矩阵的列数与行数不相等时(或反之)。例如:
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
corval <- findCorrelation(cor(as.matrix(train)), cutoff = 0.80, verbose = FALSE, names = FALSE)
“corval”表示相关性值,“train”是数据框名称。