caretEnsemble:组件模型没有相同的重采样策略
caretEnsemble: Component models do not have the same re-sampling strategies
我有几个使用相同 trainControl
创建的预测模型。这些模型必须事先创建(即我不能使用 caretList
同时训练多个模型)。
下面是我的最小示例。当我手动组合多个(已经创建的)模型并将它们传递给 caretStack
、
library("kernlab")
library("rpart")
library("caret")
library("caretEnsemble")
trainingControl <- trainControl(method='cv', number=10, savePredictions = "final", classProbs=TRUE)
data(spam)
ds <- spam
tr <- ds[sample(nrow(ds),3221),]
te <- ds[!(rownames(ds) %in% rownames(tr)),]
model <- train(tr[,-58], tr$type, 'svmRadial', trControl = trainingControl)
model2 <- train(tr[,-58], tr$type, 'rpart', trControl = trainingControl)
multimodel <- list(svm = model, nb = model2)
class(multimodel) <- "caretList"
stack <- caretStack(multimodel, method = "rf", metric = "ROC", trControl = trainingControl)
库抛出错误:
Component models do not have the same re-sampling strategies
.
为什么会这样,因为我使用相同的策略来生成基本模型?
我在 github 讨论 zachmayer/caretEnsemble/issues/104
中找到 "casting" to caretList class。
你快到了。要记住的一件事是,当您想使用 caretEnsemble 时,在 trainControl
中,您必须通过 trainControl
中的 'index' 选项设置重采样索引。如果您 运行 caretList 它往往会自行设置,但最好自己设置。当您 运行 caretList 之外的不同模型时尤其如此。您需要确保重采样是相同的。您也可以在您引用的 github 上的示例中看到这一点。
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
这将确保您的代码 运行。
请注意,在您提供的示例代码中,它将 return 出错。
我有几个使用相同 trainControl
创建的预测模型。这些模型必须事先创建(即我不能使用 caretList
同时训练多个模型)。
下面是我的最小示例。当我手动组合多个(已经创建的)模型并将它们传递给 caretStack
、
library("kernlab")
library("rpart")
library("caret")
library("caretEnsemble")
trainingControl <- trainControl(method='cv', number=10, savePredictions = "final", classProbs=TRUE)
data(spam)
ds <- spam
tr <- ds[sample(nrow(ds),3221),]
te <- ds[!(rownames(ds) %in% rownames(tr)),]
model <- train(tr[,-58], tr$type, 'svmRadial', trControl = trainingControl)
model2 <- train(tr[,-58], tr$type, 'rpart', trControl = trainingControl)
multimodel <- list(svm = model, nb = model2)
class(multimodel) <- "caretList"
stack <- caretStack(multimodel, method = "rf", metric = "ROC", trControl = trainingControl)
库抛出错误:
Component models do not have the same re-sampling strategies
.
为什么会这样,因为我使用相同的策略来生成基本模型?
我在 github 讨论 zachmayer/caretEnsemble/issues/104
中找到 "casting" to caretList class。
你快到了。要记住的一件事是,当您想使用 caretEnsemble 时,在 trainControl
中,您必须通过 trainControl
中的 'index' 选项设置重采样索引。如果您 运行 caretList 它往往会自行设置,但最好自己设置。当您 运行 caretList 之外的不同模型时尤其如此。您需要确保重采样是相同的。您也可以在您引用的 github 上的示例中看到这一点。
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
这将确保您的代码 运行。
请注意,在您提供的示例代码中,它将 return 出错。