2016-04-29 91 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