caretEnsemble: Component models do not have the same re-sampling strategies
I have several prediction models which are created using the same trainControl
. These models have to be created beforehand (i.e. I can't use caretList
to train multiple models simultaneously).
Below is my minimal example. When I manually combine multiple (already created) models and pass them to 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)
the library throws the error:
Component models do not have the same re-sampling strategies
.
Why is that since I'm using the same strategy to generate the base models?
I found the "casting" to caretList class in the github discussion zachmayer/caretEnsemble/issues/104
.
r r-caret
add a comment |
I have several prediction models which are created using the same trainControl
. These models have to be created beforehand (i.e. I can't use caretList
to train multiple models simultaneously).
Below is my minimal example. When I manually combine multiple (already created) models and pass them to 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)
the library throws the error:
Component models do not have the same re-sampling strategies
.
Why is that since I'm using the same strategy to generate the base models?
I found the "casting" to caretList class in the github discussion zachmayer/caretEnsemble/issues/104
.
r r-caret
add a comment |
I have several prediction models which are created using the same trainControl
. These models have to be created beforehand (i.e. I can't use caretList
to train multiple models simultaneously).
Below is my minimal example. When I manually combine multiple (already created) models and pass them to 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)
the library throws the error:
Component models do not have the same re-sampling strategies
.
Why is that since I'm using the same strategy to generate the base models?
I found the "casting" to caretList class in the github discussion zachmayer/caretEnsemble/issues/104
.
r r-caret
I have several prediction models which are created using the same trainControl
. These models have to be created beforehand (i.e. I can't use caretList
to train multiple models simultaneously).
Below is my minimal example. When I manually combine multiple (already created) models and pass them to 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)
the library throws the error:
Component models do not have the same re-sampling strategies
.
Why is that since I'm using the same strategy to generate the base models?
I found the "casting" to caretList class in the github discussion zachmayer/caretEnsemble/issues/104
.
r r-caret
r r-caret
edited Nov 13 '18 at 11:15
Heikki
1,2831018
1,2831018
asked Nov 13 '18 at 11:02
53c53c
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are almost there. One of the things to remember is that when you want to use caretEnsemble is that in trainControl
you have to set the resample index via the 'index' option in trainControl
. If you run caretList it tends to set this itself, but it is better to do this yourself. This is especially true when you run different models outside of caretList. You need to make sure the resampling is the same. You can also see this in the example on github you refer to.
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
This will make sure that your code will run.
Note that in the example code you have given, it will return with errors.
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279586%2fcaretensemble-component-models-do-not-have-the-same-re-sampling-strategies%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are almost there. One of the things to remember is that when you want to use caretEnsemble is that in trainControl
you have to set the resample index via the 'index' option in trainControl
. If you run caretList it tends to set this itself, but it is better to do this yourself. This is especially true when you run different models outside of caretList. You need to make sure the resampling is the same. You can also see this in the example on github you refer to.
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
This will make sure that your code will run.
Note that in the example code you have given, it will return with errors.
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
add a comment |
You are almost there. One of the things to remember is that when you want to use caretEnsemble is that in trainControl
you have to set the resample index via the 'index' option in trainControl
. If you run caretList it tends to set this itself, but it is better to do this yourself. This is especially true when you run different models outside of caretList. You need to make sure the resampling is the same. You can also see this in the example on github you refer to.
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
This will make sure that your code will run.
Note that in the example code you have given, it will return with errors.
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
add a comment |
You are almost there. One of the things to remember is that when you want to use caretEnsemble is that in trainControl
you have to set the resample index via the 'index' option in trainControl
. If you run caretList it tends to set this itself, but it is better to do this yourself. This is especially true when you run different models outside of caretList. You need to make sure the resampling is the same. You can also see this in the example on github you refer to.
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
This will make sure that your code will run.
Note that in the example code you have given, it will return with errors.
You are almost there. One of the things to remember is that when you want to use caretEnsemble is that in trainControl
you have to set the resample index via the 'index' option in trainControl
. If you run caretList it tends to set this itself, but it is better to do this yourself. This is especially true when you run different models outside of caretList. You need to make sure the resampling is the same. You can also see this in the example on github you refer to.
trainingControl <- trainControl(method='cv',
number=10,
savePredictions = "final",
classProbs=TRUE,
index=createResample(tr$type)) # this needs to be set.
This will make sure that your code will run.
Note that in the example code you have given, it will return with errors.
answered Nov 13 '18 at 12:36
phiverphiver
13.4k92835
13.4k92835
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
add a comment |
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
You are absolutely right. I fiddled around this option, but it wasn't until I completely cleared the whole environment and re-run the code that it started working. Thanks very much!
– 53c
Nov 13 '18 at 13:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279586%2fcaretensemble-component-models-do-not-have-the-same-re-sampling-strategies%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown