zachmayer / caretEnsemble

caret models all the way down :turtle:
Other
226 stars 75 forks source link

issue #187 (predict fails for models with "custom" names) not solved for xgboost #244

Open danpon opened 5 years ago

danpon commented 5 years ago

The issue https://github.com/zachmayer/caretEnsemble/issues/187 is not fixed for xgboost.

The following R code fails with Error in eval(predvars, data, env) : object 'xgb' not found It works if the model is named "xgbTree" instead of "xgb"

`` require(data.table) require(caret) require(caretEnsemble) data(iris) iris <- data.table(iris) iris[, Species := factor(ifelse(Species == "setosa", "SETOSA", sample(c("SETOSA", "OTHERS"), 200, replace = T)))]

set.seed(42) trainIndex <- createDataPartition(iris$Species, p = .8, list=F)

train <- iris[trainIndex] test <- iris[-trainIndex]

my_control <- trainControl( method="cv", number=3, index=createResample(train$Species, 3), savePredictions="final", classProbs=TRUE, summaryFunction=twoClassSummary )

xgb_grid = expand.grid( nrounds = 10, eta = c(0.1), max_depth = c( 2), gamma = 1, colsample_bytree =0.655, min_child_weight = 1, subsample = 1 )

model_list <- caretList( Species~., data=train, trControl=my_control, metric="ROC", tuneList=list( xgb=caretModelSpec(method="xgbTree", tuneGrid=xgb_grid), rf=caretModelSpec(method="rf", tuneGrid= expand.grid(.mtry = c(round(sqrt(ncol(train)))))) ) )

greedy_ensemble <- caretEnsemble( model_list, metric="ROC", trControl=trainControl( number=2, summaryFunction=twoClassSummary, classProbs=TRUE )) summary(greedy_ensemble)

predict(greedy_ensemble, newdata=test, type="prob") ``

hermandr commented 4 years ago

Hi,

Look at the list of available models in Caret https://topepo.github.io/caret/available-models.html

No "xgb" only xgbTree, xgbDART, xgbLinear

Herman