Probability prediction for GBM using a carriage library

A similar question was asked , however, the link in the answer points to a random example of a forest, it does not seem to work in my case.

Here is an example of what I'm trying to do:

gbmGrid <-  expand.grid(interaction.depth = c(5, 9),
                    n.trees = (1:3)*200,
                    shrinkage = c(0.05, 0.1))

fitControl <- trainControl(
                       method = "cv",
                       number = 3,
                       classProbs = TRUE)

gbmFit <- train(strong~.-Id-PlayerName, data = train[1:10000,],
             method = "gbm",
             trControl = fitControl,
             verbose = TRUE,
             tuneGrid = gbmGrid)
gbmFit

Everything is going well, I get the best options. Now, if I make a prediction:

predictStrong = predict(gbmFit, newdata=train[11000:50000,])

I get a binary forecast vector, which is good:

[1] 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 ...

However, when I try to get the probabilities, I get the error message:

predictStrong = predict(gbmFit, newdata=train[11000:50000,], type="prob")

Error in `[.data.frame`(out, , obsLevels, drop = FALSE) : 
undefined columns selected

Where is the problem apparently?

Additional Information:

traceback()
5: stop("undefined columns selected")
4: `[.data.frame`(out, , obsLevels, drop = FALSE)
3: out[, obsLevels, drop = FALSE]
2: predict.train(gbmFit, newdata = train[11000:50000, ], type = "prob")
1: predict(gbmFit, newdata = train[11000:50000, ], type = "prob")

Versions:

R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

caret version: 6.0-29

EDIT: I saw this section , and I do not receive a message about variable names, although I have a couple of variable names with underscores, which I consider valid as I use make.namesand get the same names as the original.

colnames(train) == make.names(colnames(train))
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
+4
3

, train . , (, "0" "X0"). train , : " R. , ".

+9

, .

:

make.names(levels(traintestClass_subset))

, , . , , , , , .

+1

:

, :

[1] 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1...

. , , 0 'a' 1 'b', , .

0

Source: https://habr.com/ru/post/1543554/


All Articles