2016-04-29 89 views
0

尝试从rfe对象中提取混淆矩阵时遇到错误“重新抽样的混淆矩阵不可用”。是caret包的confusionMaitrx.rfe函数不工作,或者我在这里丢失了什么?confusionMatrix.rfe中的错误:无法重新采样混淆矩阵

下面是一个使用从

http://topepo.github.io/caret/rfe.html

文档的功能confusionMatrix.rfe模拟数据的例子是在这里

http://www.inside-r.org/packages/cran/caret/docs/confusionMatrix.train

library(caret) 
library(mlbench) 
library(Hmisc) 
library(randomForest) 
n <- 100 
p <- 40 
sigma <- 1 
set.seed(1) 
sim <- mlbench.friedman1(n, sd = sigma) 
colnames(sim$x) <- c(paste("real", 1:5, sep = ""), 
        paste("bogus", 1:5, sep = "")) 
bogus <- matrix(rnorm(n * p), nrow = n) 
colnames(bogus) <- paste("bogus", 5+(1:ncol(bogus)), sep = "") 
x <- cbind(sim$x, bogus) 
y <- sim$y 
normalization <- preProcess(x) 
x <- predict(normalization, x) 
x <- as.data.frame(x) 
subsets <- c(1:5, 10, 15, 20, 25) 
set.seed(10) 

ctrl <- rfeControl(functions = lmFuncs, 
       method = "repeatedcv", 
       repeats = 5, 
       verbose = FALSE) 

lmProfile <- rfe(x, y, 
      sizes = subsets, 
      rfeControl = ctrl) 

lmProfile 
confusionMatrix(lmProfile) 
**Error in confusionMatrix.rfe(lmProfile) : 
    resampled confusion matrices are not availible** 

谢谢!

回答

0

mlbench.friedman1是一个回归问题,而不是分类问题。如果你检查数据,你可以看到你的Y变量是连续的。 confusionMatrix在这种情况下没有用处。

+0

你是对的!谢谢。 – ybeybe