繁体   English   中英

为什么函数引导返回的值与引导内部使用的统计数据的类型不同?

[英]Why does function boot return values of different types than those from the statistic used inside boot?

我正在运行分类方法Bagging Tree(Bootstrap Aggregation) ,并将此错误分类错误率与一棵树中的错误分类错误率进行比较。

这对我来说很奇怪,因为函数estim.pred返回一个映射到“pos”和“neg”的因子矩阵,但res.boot$t返回一个取值为 1 或 2 的整数矩阵,其中作为estim.predres.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)

在此处输入图片说明

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM