这是一个占位符答案,但首先要注意的是,您的观察得到的交叉验证不到 10 次:
library(pROC)
library(dplyr)
filenameROC = "Data/term3_IBk_3_multiclass.txt"
fileROC = readLines(filenameROC)
dfCV = read.csv2(text = fileROC,
nrows = length(fileROC) - 51 - 19,
header = TRUE,
sep = ",",
skip = 19, stringsAsFactors = FALSE)
dfCV %>%
group_by(inst.) %>%
tally() %>%
filter(n < 10)
这给出了:
> dfCV %>%
+ group_by(inst.) %>%
+ tally() %>%
+ filter( n < 10)
Source: local data frame [1 x 2]
inst. n
1 773 4
你能解释一下吗?
此外,您还需要添加交叉验证迭代标识符。一旦你这样做了,这只是一个通过 CV 迭代从 pROC 包中运行 multiclass.roc 的问题。
编辑:
OP 声称有 7724 个 *observations ,而很容易看出有 773 个观察结果在 772 个案例中重复了 10 次,对于第 772 个观察结果重复了 4 次 - 与 10 倍交叉验证数据一致:
> dfCV %>%
+ group_by(inst.) %>%
+ tally()
Source: local data frame [773 x 2]
inst. n
1 1 10
2 2 10
3 3 10
4 4 10
5 5 10
6 6 10
7 7 10
8 8 10
9 9 10
10 10 10
.. ... ..
编辑 2:
下面是通过 CV 折叠生成多类 ROC 的代码:
dfCVROC = dfCV %>%
dplyr::filter(inst. != 773) %>%
arrange(inst.) %>%
dplyr::mutate(cvfold = rep.int(1:10, 772)) %>%
group_by(cvfold) %>%
do(multiclass_roc = multiclass.roc(as.factor(.$actual), as.numeric(.$prediction)))
# get the AUCs by CV fold
sapply(dfCVROC$multiclass_roc, function(x) x$auc)