I'm fighting with this issue for an embarrassingly long time. I feel like an absolute cretin, as the answer is probably painfully obvious, but I can not find a single thread that explains how to do this.
Documentation part about custom model creation feels for me like this. I feel like somewhere during my education I missed some very specific class, that everybody remembers now, but me, because all I find is "yea, just create a custom model, and done".
Actual questions here:
I want to get predictions for every single iteration of gbm
in caret
. In gbm
I can just use n.trees
in predict(..., n.trees = 1:100)
for example, and it's done.
In caret
apparently for I need to use something called sub-models trick, which means - if I understand correctly - that I have to create my own custom model.
But I can see in getModelInfo('gbm')
, that there is some kind of loop function!
$gbm$loop
function (grid)
{
loop <- plyr::ddply(grid, c("shrinkage", "interaction.depth",
"n.minobsinnode"), function(x) c(n.trees = max(x$n.trees)))
submodels <- vector(mode = "list", length = nrow(loop))
for (i in seq(along = loop$n.trees)) {
index <- which(grid$interaction.depth == loop$interaction.depth[i] &
grid$shrinkage == loop$shrinkage[i] & grid$n.minobsinnode ==
loop$n.minobsinnode[i])
trees <- grid[index, "n.trees"]
submodels[[i]] <- data.frame(n.trees = trees[trees !=
loop$n.trees[i]])
}
list(loop = loop, submodels = submodels)
How do I use that? Why is it not working by default? Do I actually need to create a custom model - or maybe not?
Disclaimer 1: I do not want to use any crossvalidation. I just want to pull out predictions, for every iteration of a single gbm run.
Disclaimer 2: I don't want to use predict.gbm()
on $finalModel
, as I want to also test some other algorithms, which also make use of that sub-model trick. I do not want to use all the different algorithm specific predict()
functions, because then why should I even bother with caret.
I do not even know what should I put as a replicable example. There is no problem with the code. I just have no idea how this thing is supposed to work.