Repository navigation
Parameter tuning with train fails when using 'method = xgbTree' #1412
Description
Activity
Background
I have the same issue, and after some digging, I suspect that the problem is how caret handles xgboost attributes. The result of xgb.train() doesn't have 'normal' list elements that can be accessed withfit$name. However, when looking into caret:::varImpDependencies("xgbTree"), it does try to access elements that don't exist.Suspected issue
The main issue in your (and my) workflow is probably after fitting, when caret callscaret:::varImpDependencies("xgbTree")$prob(fit, newdata = dmatrix), which results in a more informative error, namelyError in matrix(out, ncol = length(modelFit$obsLevels), byrow = TRUE) : data is too long Called from: matrix(out, ncol = length(modelFit$obsLevels), byrow = TRUE)Inspecting this line of code reveals that
modelFit$obsLevelsdoesn't exist and itslengthis0L. Note that this specific functioncaret:::varImpDependenciesmay only be used byvarImp, but it's likely that the core of the problem is the same.Potential solution
I think that the solution is to internally adjust this code to usexgboost::xgb.config(fit)as much as possible, or any other function used by xgboost to access the relevant elements. I don't know enough about caret to confirm that this is really the issue, but bypassing theif (length(modelFit$obsLevels) == 2) {seems to work.Reacted by Ceres BarrosSame issue as you. You might consider switching to a new workflow. As the age of the updates in the codebase indicate, this library is in maintenance mode. I say that based on the comment from Mr. Flick here: https://stackoverflow.com/questions/79849114/new-version-of-xgboost-package-is-not-working-under-caret-environment
Reacted by Ceres BarrosThank you @John-Polo and @selbouhaddani.
Unfortunately switching the workflow is not doable in this particular case, but good to know thattidymodelscan accomodate XGBoost.I have since forked the
caretrepository and found a way to fix the problem for the XGBoost implementation that I needed.
I can't guarantee that it'll will work for all XGBoost implementations, but it's a start.Feel free to see if it works for you:
https://github.com/CeresBarros/caretReacted by John Polo
I've been a user of
caretfor several years now and want to start by saying, THANKS for the awesome package.I've recently started using it to tune parameters for an XGBoost model, but so far without success.
I think I've traced the issue to a problem with assigning colnames(x) to the xgboost model object.
Here's a reprex:
the output
And my session info: