Я использую метод классификации Дерево мешков (Bootstrap Агрегация) и сравните эту ошибку ошибочной классификации с одним из одного отдельного дерева.
Это странно для меня, потому что функция estim.pred
возвращает матрицу факторов, которые отображаются в «pos» и «neg», но res.boot$t
возвращает матрицу целых чисел, принимающую значения 1 или 2, где estim.pred
- статистика c из 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)