Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 为什么函数boot返回的值与boot内部使用的统计值不同?_R_Function_Machine Learning_Bootstrap 4 - Fatal编程技术网

R 为什么函数boot返回的值与boot内部使用的统计值不同?

R 为什么函数boot返回的值与boot内部使用的统计值不同?,r,function,machine-learning,bootstrap-4,R,Function,Machine Learning,Bootstrap 4,我正在运行分类方法Bagging Tree(Bootstrap聚合)并将此错误分类率与单个树的错误分类率进行比较 这对我来说很奇怪,因为函数estim.pred返回一个映射到“pos”和“neg”的因子矩阵,但是res.boot$t返回一个值为1或2的整数矩阵,其中asestim.pred是res.boot$t的统计 你能解释一下这种现象的原因吗 library(rpart) library(boot) library(mlbench) data(PimaIndiansDiabetes) n

我正在运行分类方法Bagging Tree(Bootstrap聚合)并将此错误分类率与单个树的错误分类率进行比较

这对我来说很奇怪,因为函数
estim.pred
返回一个映射到“pos”和“neg”的因子矩阵,但是
res.boot$t
返回一个值为1或2的整数矩阵,其中as
estim.pred
res.boot$t
的统计

你能解释一下这种现象的原因吗

library(rpart)
library(boot)
library(mlbench)
data(PimaIndiansDiabetes)

n <- 768
ntrain <- 468
ntest <- 300
B <- 100
M <- 100
train.error <- vector(length = M)
test.error <- vector(length = M)
bagging.error <- vector(length = M)

estim.pred <- function(a.sample, vector.of.indices)
      {
      current.train <- a.sample[vector.of.indices, ]
      current.fitted.model <- rpart(diabetes ~ ., data = current.train, method = "class")
      predict(current.fitted.model, test.set, type = "class")
      }

fitted.tree <- rpart(diabetes ~ ., data = train.set, method = "class")
pred.train <- predict(fitted.tree, train.set, type = "class")
res.boot = boot(train.set, estim.pred, B)

head(pred.train)
head(res.boot$t)
库(rpart)
库(启动)
图书馆(mlbench)
数据(PImaindansDiabetes)

这里是@Roland评论。我把它贴在这里是为了把我的问题从未回答的列表中删除


res.boot$t
是一个矩阵。矩阵不能包含因子变量。因此,矩阵包含基础整数值。转换矩阵,将其转换为data.frame,并将整数转换为因子变量(与您的级别一致)


res.boot$t
是一个矩阵。矩阵不能包含因子变量。因此,矩阵包含基础整数值。转换矩阵,将其转换为data.frame,并将整数转换为因子变量和您的级别。@Roland您的意思是从
res.boot$t
返回的整数对应于因子的字母顺序,对吗?是的,与
unclass(head(pred.train))
比较。